Displaying 1 result from an estimated 1 matches for "product_attrs".
2006 Dec 05
7
Dynamic # of Attributes for a Model (key/val table) Get/Set?
...roduct catalog. Products have user defined
attributes, such as: color, size, weight. More attributes can be added
at any time. Since these attributes are not known ahead of time, they
cannot be created as columns.
My table structure (simplified):
products
--------
id
name
attrs
--------
id
name
product_attrs
--------
id
attr_id
value
And some sample code:
## Create some attributes
## 1 - size
## 2 - color
## 3 - weight
[''size'',''color'',''weight''].each do |attr|
Attr.create( { ''name'' => attr } )
end
## Create a new pr...