Cakephp inherited tables

44 views Asked by At

I have the following situation with three tables, which are inherited from

contactBasics contactSales (foreign key of contactBasics) contactSupporters (foreign key of contactBasics)

  • The general data about a person is stored in contactBasics
  • Specific data about Sales People are additionally stored in contactSales
  • Specific data about Supporting People are additionally stored in contactSupporters

Is there a good way to handle e.g. contactBasics and contactSales as one object in code ?

help appreciated. Endo

1

There are 1 answers

0
Dave On

Assuming there is very similar data between contactSales and contactSupporters, you could just to have a 'contacts' table and add a contact_type field that clarifies which type of contact it is.

This also allows you to expand should you ever need another contact type.

You can use a short string field and have it be 'sales' or 'supporter', or you can go with an int field and have 1 = sales, 2 = supporter...etc. Which of those is up to your preference and app needs.

You can still keep both models if you want/need. In your associations, you can add conditions to differentiate between the two.

(or here for cake 3)