i have model product
, has 2 types: lamps
, bulbs
. lamp have set of attributes differs bulb, have 2 models lamp
, bulb
represent set of attributes. type of relation product attribute model should implement in situation?
i've been trying one-to-one relation, in situation second "one" differs product's type.
i've been thinking of eav pattern, don't want tons of joins in architecture right because don't need more these 2 types of item.
what suggest?
upd1: here tables (simplified):
mysql> show columns products; +-------------+--------------+------+-----+---------+----------------+ | field | type | null | key | default | | +-------------+--------------+------+-----+---------+----------------+ | id | int(11) | no | pri | null | auto_increment | | name | varchar(127) | no | | null | | | price | double | no | | null | | | old_price | double | no | | null | | | category_id | int(11) | no | | null | | +-------------+--------------+------+-----+---------+----------------+ 5 rows in set (0.00 sec) mysql> show columns lamps; +------------+---------+------+-----+---------+----------------+ | field | type | null | key | default | | +------------+---------+------+-----+---------+----------------+ | id | int(11) | no | pri | null | auto_increment | | product_id | int(11) | no | | null | | | width | int(11) | no | | null | | | height | int(11) | no | | null | | | length | int(11) | no | | null | | | weight | int(11) | no | | null | | +------------+---------+------+-----+---------+----------------+ 7 rows in set (0.00 sec) mysql> show columns bulbs; +------------+---------+------+-----+---------+----------------+ | field | type | null | key | default | | +------------+---------+------+-----+---------+----------------+ | id | int(11) | no | pri | null | auto_increment | | product_id | int(11) | no | | null | | | voltage | int(11) | no | | null | | | power | int(11) | no | | null | | | base | int(11) | no | | null | | | type | int(11) | no | | null | | +------------+---------+------+-----+---------+----------------+ 6 rows in set (0.00 sec)
upd2: understand can use 2 foreign keys in products table , set 1 of them each record, there more elegant scheme situation?
Comments
Post a Comment