I'm trying to implement the EAV pattern in ActiveRecord, for that case
I've create two models: Product and ProductType and based on what
ProductType your product is you get dynamically defined accessors.
This way you can use the dynamic attributes by all AR methods, like
#update_attributes, etc. But you can't directly pass a hash with
dynamic attributes to new.
See the code here: https://github.com/edzhelyov/product_manager/blob/master/app/models/product.rb#L5
And the corresponding test: https://github.com/edzhelyov/product_manager/blob/master/spec/product_spec.rb#L97
The test fails with the following:
Failure/Error: product = @pt.products.create :price => 10, :ram
unknown attribute: ram
# ./app/models/product.rb:6:in `initialize'
# ./spec/product_spec.rb:98:in `block (3 levels) in <top
This is because the AR#initialize try to call #ram= which is not
if I first try to define the dynamic attributes I don't have access to
the product_type relation, interesting thing is that I can't even
access it from the attributes when called with this:
Does anyone have any idea how I can make this pass ?
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to email@example.com.
To unsubscribe from this group, send email to firstname.lastname@example.org.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.