Reputation: 119
If you have a complex database structure where many of your select statements involve complex joins is it best to use 1 model or do you have to break each table into it's own model?
For example if I have a database that has the following
And I need to pass data to my views from SQL statements like
select c.interest_type_name
from tb_persons a
LEFT JOIN tb_interests b on (a.persons_id=b.persons_id)
LEFT JOIN tb_interests_types c on (b.interest_type_id=c.interest_type_id)
WHERE a.person_id=1
What model would this go into? Can you treat a model as a holder for a group of tables that relate together or do you need to have individual models?
Upvotes: 0
Views: 280
Reputation: 9547
I would have a person model, and then join the interests on an as-needed basis.
As stated in a comment, you don't need a model-per-table structure, but you probably need a model per strong entity (an interest is worthless without a "person" context, but a person object can be valuable without interests).
Upvotes: 2