I''ve got a has_many collection of classes that validated uniqueness
of one of its fields. When I try to create a new object in this
collection, the validation fails but the object is added to the
collection anyways. Is this the expected behavior? If not, how do I
keep new objects that fail validation out of the collection?
class A
belongs_to :b
end
class B
has_many :c
end
class C
validates_uniqueness_of :name
end
from the rails console I can say:
>> a = A.find(:first)
=> [#A:0x....]
>> a.b.c.size
=> 4 (assume one of those records has a name of "don")
a.b.c.create(:name => "don")
=> [#C:0x... ,@errors=...{code="has already been taken"}]
>> a.b.c.size
=> 5
Since the validation failed, shouldn''t the new C object be kept from
joining the other C objects?
Don
_______________________________________________
Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails