Shouldn't you be validating presence of the key rather than the object itself?
On Apr 22, 2009, at 2:29 PM, Eloy Duran wrote: > > I agree. Please write a patch :) > > Eloy > > On 22 apr 2009, at 18:18, hakunin wrote: > >> >> (Just posted it in Talk and realized it makes more sense to ask >> here.) >> >> Simple example. >> >> class Car < ActiveRecord::Base >> has_one :engine >> >> validates_presence_of :engine >> validates_associated :engine >> end >> >> class Engine < ActiveRecord::Base >> belongs_to :car >> >> validates_presence_of :car >> end >> >> @car = Car.new >> @car.valid? # => false >> @car.errors # => no engine obviously >> >> @car.build_engine >> @car.valid? # => false >> >> How come?? >> >> @car.errors # => engine has no car! >> @car.engine.car # => nil >> >> Since we validate_associated :engine, engine runs its own validations >> and finds that validates_presence_of car is false, since car is nil. >> Shouldn't engine know the car that built it? >> >> Just for fun I do this: >> >> @car.engine.car = @car >> @car.valid? # => true >> >> Shouldn't this work by default? >>> > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---