protected static $_has_one = array( 'person' => array( 'key_from' => 'person_id', 'key_to' => 'id', 'cascade_save' => true, 'cascade_delete' => true, ) );ORM complains that the primary key cannot be modified, and thus this configuration doesn't work. I think it should, but I'm open to enlightenment.
- Person -- (has one) -- -- Client, User or Employee -- (has many) -- Addresses
Model_Person::find('first')->where('id', $id)->related('client')->related('addresses')->get_one();
Frank Bardon wrote on Tuesday 26th of July 2011:Would it be better to have a structure more like this?
- Person -- (has one) -- -- Client, User or Employee -- (has many) -- Addresses
Person would have client_id, user_id, employee_id.
And Client, User, Employee and Address would have person_id. Add 'type' to Address so it can be identified as either, client, user or employee. Then you could use nested relations to call any from anywhere. A Person would be the base of all, not the other way around. Person holds all of the information. Client, User and Employee adds relevant information to the Person model... and addresses are attached per person, not per Client, User or Employee... but they could still be matched to the 'type' of Model they need to be identified with... This way you could useModel_Person::find('first')->where('id', $id)->related('client')->related('addresses')->get_one();
Would that make sense, sorry if I'm not fully following what you need.
It looks like you're new here. If you want to get involved, click one of these buttons!