S
S
Sergey Erin2021-04-26 14:10:37
Yii
Sergey Erin, 2021-04-26 14:10:37

How to implement search by synonyms?

I use the autocomplete widget to search the table of games and the table of synonyms. For games, the search works, the problem is when searching in the field by synonym. Tell me, how can I connect the search and by synonyms? There is very little information in the docs. Here is the code:

<?php $data = Game::find()
                    ->select([
                        'game.name as value',
                        'game.name as  label',
                        'game.id as id',
                        'synonym.name as name'
                    ])
                    ->leftJoin('game_synonym', 'game_synonym.game_id = game.id')
                    ->leftJoin('synonym', 'synonym.id = game_synonym.synonym_id')
                    ->asArray()
                    ->all(); ?>

                <?= AutoComplete::widget([
                    'name' => 'Company',
                    'id' => 'ddd',
                    'clientOptions' => [
                        'source' => $data,
                        'autoFill' => true,
                        'minLength' => '1',
                        'maxShowItems' => 5,
                        'select' => new JsExpression("function( event, ui ) {
                                $('#game').val(ui.item.id);
                            }"),
                    ],
                    'options' => [
                        'class' => 'game-input',
                        'placeholder' => '*Название игры',
                    ],
                ]);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya, 2021-04-26
@rpsv

And you look at what the request returns to you, and then I think everything will be clear: in your select 2 fields have an alias `name`.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question