cakephp Database Design -


my data structure follows:

company hasmany regions region hasmany markets market hasmany stores store hasmany employees 

i have appropriate belongsto necessary.

i used foreign keys associations. example, each store has market_id.

when delete company record, correct region deleted. however, occurred me need associated markets, stores, , employees deleted. or if deleted market, need stores , employees deleted.

what appropriate manner of accomplishing this?

  1. would add additional foreign keys tables? example, stores need region_id , company_id in addition market_id?

use dependent association:

http://book.cakephp.org/2.0/en/models/associations-linking-models-together.html#hasmany

dependent: when dependent set true, recursive model deletion possible. in example, comment records deleted when associated user record has been deleted.

you don't need add additional foreign keys.


Comments

Popular posts from this blog

php - cannot display multiple markers in google maps v3 from traceroute result -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -