A
A
AR2017-01-06 06:44:27
Yii
AR, 2017-01-06 06:44:27

Why is there an incorrect loading of data from the associated table into the select?

Good morning.
There is a form in which there is a select. Data from another table is loaded into this select. The table consists of id and name.

<?php echo $form->field($model, 'id_type')->dropdownList(Type::find()->
select(['name'])->indexBy('name')->column(), ['prompt'=>'Выберите услугу']);?>

for some reason, after submitting the form, 0 comes to id_type, although there are no records with id equal to 0 in the type table.
And if you do that, the correct id comes, but the indexing is already going wrong, according to the name field, but according to the id field. What could be the problem? select(['name'])->indexBy('id')

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Timofeev, 2017-01-06
@amio

And if so?

ArrayHelper::map(Type::find()->select(['id','name'])->all(),'id','name')

P
Pavel, 2017-01-06
@BoRzZoY

Maybe because there is no index on 'name' in the table?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question