Welcome Guest, Not a member yet? Register   Sign In
1 controller = 1 model VS. 1 controller = multiple model
#18

(08-28-2018, 09:25 PM)albertleao Wrote:
(08-27-2018, 05:11 PM)skunkbad Wrote: So then how do you handle joins?

Mostly in libraries.

In my workflow, if the join is pulling in child data, I use a function within the parent model. For example, if you have 1 blog post with 10 tags, I'd have a function called 'tags()' in my BlogPost model that I could call to get related data.


I do have some models with join statements but I try to keep them as clean as possible. Keeping separation can make a huge difference down the road if your app gets big.

To illustrate what you would do, how about something like this:

Code:
SELECT *
FROM A
LEFT JOIN B
ON A.id = B.a_id
WHERE A.foo = "bar"
Reply


Messages In This Thread
RE: 1 controller = 1 model VS. 1 controller = multiple model - by skunkbad - 08-30-2018, 11:41 AM



Theme © iAndrew 2016 - Forum software by © MyBB