M
M
m4tkv2019-10-18 18:56:48
Yii
m4tkv, 2019-10-18 18:56:48

How to merge yii2 models?

I am using yii2. There are 2 tables, conditionally user(id,address,...) and profile(id,user_id,...) 1: n. The user table has data, such as an address, that pertains to each user profile. Created through gii 2 ActiveRecords models. In the controller I call the static function Profile::getProfiles(condition)

function static getProfiles(condition){
       return self::find()->where(condition)—>all();
}

Now I have an array of profile objects from asset records. But I want to add an address from the user table to each profile. When I add a new property to the profile object, ActiveRecords complains and does not allow adding fields that are not described. Tell me how to do it right?
You need to get an array of profiles in which to add the address by user_id

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Bay, 2019-10-18
@kawabanga

1) You don't need a static function here. We read about connections - commercito.ru/hasone-hasmany-svyazannye-dannye-vy... .
2)
- what is this action? if the address is updated, then make a request to ActiveRecord.
Otherwise, use getAddress, the magic field, with respect to hasOne on the user table.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question