i want create class table inheritance model in cakephp.
i have model called productbase
table product_bases
hold base information every product should have, upc, price, etc.
then have specific product type models extend that. example productring
table product_rings
hold specific ring information ring_size, center_stone, etc.
then if retrieve data directly productbase model, have pull types:
// pull product types $this->productbase->find('all');
or find specific types only:
// pull rings or descendants of ring type. $this->productring->find('all');
is possible in cakephp? if not, should doing instead?
what proper cake way of doing this?
you referring arc relationship (or @ least variation of it). cake not handle these types of relationships on fly. means have implement won logic handle this.
the other option categorize products. if product can fit multiple categories, want habtm categories each product. otherwise, can use category column. suspect habtm looking for.
- products: table holds products.
- categories: list of categories given product can belong to.
- categories_products: link between each product , various categories.
- type: flag define type of product (i.e. ring, shoe, pants, etc.)
then when want products, query products table. when want slice of products (i.e. rings) select products belongs ring category.
now, need address information product. example, not information apply every product. there number of ways this.
- you can build multiple tables hold product information. when pull product of given type, pull companion information table.
- store information in text field serialized data. of information can defined in settings var , can use serialized data map information.
i hope helps. happy coding!
Comments
Post a Comment