How Many HABTM relationships in cakephp is too many?
I'm struggling with deciding how many HABTM relationships I really need in my cakephp app. I guess I don't quite get what "has" truly means. I don't want to have more HABTM tables than necessary. Here's what I have in my database:
Users
Properties
Leases
Payments
Repairs
user
HABTM properties
, user
HABTM leases
, user
HABTM users
, user
HABTM repairs
, property
hasMany repairs
, property
hasMany leases
, lease
hasMany repairs
.
Also, I have two aliases for my users
model (manager
an开发者_Python百科d tenant
). This is one of the reasons I ended up with so many HABTM relationships, but I'm not sure it's necessary.
Do I have too many user HABTM relationships? Would it be better to just have cake recurse through my models?
Thanks!
This is a rather subjective question. That is to say one only you can decide as you know your code. The best thing to do is ask yourself if the following is strictly true: X really has and belongs to many Y?
For example, does User
really have many Payment
? Or does User
have a Lease
and the Lease
has Payments
? Same with Repairs
and Properties
.
As far as CakePHP having too many, I wouldn't worry about that. Setting the recursive
property on your find()
, using Containable
, or un/bindModel()
will also help limit when all these relationships are used.
精彩评论