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?
- 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
Post a Comment