hzamani / acts_as_relation

Multi table Inheritance for rails
http://hzamani.github.com/acts_as_relation/
MIT License
180 stars 58 forks source link

validation issue? #15

Closed rforte closed 12 years ago

rforte commented 12 years ago

Not sure why in your example validation is failing on creating a Pen:

Pen.create :name => "Nice Pen", :price => 1.3, :color => "Red"
Pen.where "name = ?", "Some Pen"
pen = Pen.new
pen.valid?      # => false
pen.errors.keys # => [:name, :price]
Pen.first.to_s  # => "Nice Pen $1.3"

A pen object is being created with a name and a price so why is pen.errors showing name/price as validation errors?

hzamani commented 12 years ago

because pen is a new pen with :name, :price, :color set to nil you must call .valid? and .errors on created pen!

rforte commented 12 years ago

oooh, totally misread the code where pen = Pen.new. Was looking at Pen.create :name => "Nice Pen", :price => 1.3, :color => "Red" and thought that was the 'pen' instance it was using. Hence the confusion. Thanks.