I have model named User and UserPhoto, which is related in one user to many user photo
$this->hasMany("id", "UserPhoto", "user_id"); $this->belongsTo("user_id", "User", "id");
If I try
$userData = User::find();
foreach ($userData as $user) { $userPhotoAry = $user->UserPhoto; }
I am getting relational resultset, but i need only selected column from table.
So I tried this,
$userData = User::find(array("columns"=>"id,username"));
foreach ($userData as $user) { $userPhotoAry = $user->UserPhoto; }
I am getting $UserPhoto is undefined.
Is there any way to mention column in find query along with relationship?