Welcome Guest, Not a member yet? Register   Sign In
Model with joined tables
#7

I have a userModel

Code:
[users]
user_id | name | ...


Every user have same avatar images

Code:
[avatars]
avatar_id | user_is | uri | is_dafault | ...


When I got User entity from userModel I wanna access to

PHP Code:
$User->avatars($only_default false); // return plain array or array of entities of Avatar() 


Yes, I can load avatars directly in method. But what if i need build a table of users with avatars?
I would not like to make 50 requests in a cycle.
How to do it right?
Given that I still need a list of social networks and etc

Maybe something that


PHP Code:
$Users $userModel->withAvatars()->get([1,2,3]);
$Users $userModel->withAvatars()->withSocials()->get([1,2,3]); 

Or only this way?

PHP Code:
$Users $userModel->get(...);
$Avatars $avatarModel->get(...);
foreach(
$Avatars AS $Avatar){
   $Users{$Avatar->user_id][] = $Avatar;




(sorry for my english)
Reply


Messages In This Thread
Model with joined tables - by Mni.day - 12-06-2022, 02:07 PM
RE: Model with joined tables - by InsiteFX - 12-08-2022, 12:40 AM
RE: Model with joined tables - by Mni.day - 12-08-2022, 09:01 AM
RE: Model with joined tables - by Mni.day - 12-15-2022, 02:09 AM
RE: Model with joined tables - by groovebird - 12-15-2022, 02:40 AM
RE: Model with joined tables - by Mni.day - 12-15-2022, 01:18 PM



Theme © iAndrew 2016 - Forum software by © MyBB