Welcome Guest, Not a member yet? Register   Sign In
Best practice selecting data from related models
#1

I'm trying to figure out what is the best practice with selecting data from related model.

I have a model (and a db table) "person" and then i have a model (and a db table) comment. There may be multiple comments for one person and commend has "person_id" column.

I have two cases in particular.

First i need to show persons profile with all his comments.
In my controller do I select the needed person through my person model and then select all the comments through my comments model? Or is it more correct for person model already return person with all comments?
I myself would guess that first option is ok.

Second case is where i need to show all latest comments with name of the person who made the comment.
So in my controller is it correct to select all latest comments from comments model and then select a person for each or them? Or is it more correct for the comments model to return comment with person name included?
In this case i would guess that second option is better. It seems really strange to first select comments and then iterate them and select a person for each of them.

So im kind of confused because case 1 and 2  seem similar but i would use different solutions for them. Which seems right to you guys?
Reply


Messages In This Thread
Best practice selecting data from related models - by donald.tbd - 11-19-2016, 01:36 PM



Theme © iAndrew 2016 - Forum software by © MyBB