• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Entities and pivots

Hi all- this is probably only partially CI related, but since CI4 is introducing me to Entities for the first time I figured it might others as well. I'm wondering what the best practice is for an entity handling its pivot table(s)? Consider this example:

id, firstname, lastname, email, deleted, created_at, updated_at

id, name, color, deleted, created_at, updated_at

user_id, widget_id, created_at

My simple User model return type is 'App\Entities\User', and my user Entity handles the normal stuff. Now, am iterating through $users->findAll() and want to display each user's widgets. In CodeIgniter 3 I would have a function in my user model $this->User->widgets($user->id) that returned widget_id from users_widgets, and then could use $this->Widget->get($widget_id) if I needed the whole row.
The same could be accomplished in my entity by defining getWidgets() and then I could use $user->widgets - is that how folks typically do it? Or other recommendations / example repos to check out? Do people pass around IDs or entire data rows (e.g. does getWidgets() return an int or an object/array)?
Thanks for the help!

Messages In This Thread
Entities and pivots - by MGatner - 03-08-2019, 12:39 PM
RE: Entities and pivots - by MGatner - 03-10-2019, 10:26 AM
RE: Entities and pivots - by MGatner - 03-27-2019, 04:40 PM
RE: Entities and pivots - by kilishan - 03-27-2019, 07:17 PM
RE: Entities and pivots - by MGatner - 03-28-2019, 04:59 AM
RE: Entities and pivots - by MGatner - 04-12-2019, 06:41 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.