> I have models Person and Company that share a large amount of fields
> so I'm thinking to use a single/shared table (named Contacts) to store
> the information and set both models to $useTable='contacts'.
> Obvioulsy in Contacts table I have a field type that can be 'person'
> or 'company' that I need to check on find actions and to set on save
> ones.

This is called "Single Table Inheritence" and as far as I know, there
is no built-in support planned for it in CakePHP.

There's an interesting article here :
http://www.ifisgeek.com/tutorials/implementing_single_table_inheritance_in_cakephp

> What i'm planning to do is to set beforeFind() to add the
> type='person' condition and beforeSave() to set the type field to
> 'person' (and the 'company' one for the model Company, obviously).

That's exactly what I did in a project a while ago, and it worked. But
it never seemed the "cleanest" solution. (Code extract here :
http://pastebin.com/m2b094512 )

> Or maybe I can build a behaviour (even if I never wrote one...)?
>
> Before going this way I would like to know what do you think about
> this "design": if would be better to have the two distinct tables and
> moreover if there is already built in Cake a way  to "bind" a Model to
> its own table with some conditions...

I'd also like to hear some views on this, as it's a frequently
recurring subject. There is no way to directly bind a model to a table
with constraints, but with a behavior it would be possible, with an
implementation like:

class Person extends AppModel {
  var $name = "Person";
  var $actsAs = array('Is'); // Load 'Is' behavior

  var $is = array(
    'tableName' => 'entities',
    'conditions' => "Person.type='person'"
  );

  var $belongsTo = (...)
}

or something along those lines.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to