A
A
AlexSer2018-01-18 08:54:36
css
AlexSer, 2018-01-18 08:54:36

How to find out that connected models are connected?

Tell me how to find out that connected models are correctly connected via hasMany. For example: if there are user and product tables.
there is a connection between them

public  function getTovar(){
        return $this->hasMany(Tovar::className(), ['id' => 'userID']);
          }

I know that when the connection is created correctly, then when you make calls, $model=User::find()->all();
you can see the result in the form $model->tovar.
And how to see what data $model returns and is the connection set correctly?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
profesor08, 2019-11-04
@NikitaSech

perspective(1200px)

D
Dmitry, 2018-01-18
@AlexSer

Good morning.
What do you mean?
If you look in the documentation , you will find the following methods:
1) getRelatedRecords() - will return all model relationships
2) getRelation() - will return data for a single relationship, in your case$model->getRelation('tovar')
As usual, for example through print_r($model)orprint_r($model->attributes)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question