This project is archived and is in readonly mode.

#3638 ✓resolved
Matt Swasey

Different nested validations should not be ignored

Reported by Matt Swasey | December 30th, 2009 @ 04:40 PM | in 3.0.2

This is my first ticket, be nice please.

Given the following relationship.

class Store < ActiveRecord::Base
  has_many :products
  accepts_nested_attributes_for :products
end

class Product < ActiveRecord::Base
  belongs_to :store
  validates_presence_of :name
end

If I create two nested products on a parent store, both invalid, I will only get one validation error, observe:

s = Store.new
s.products.build(:name => nil)
s.products.build(:name => nil)
s.valid?
s.errors.full_messages

=> ["Products name can't be blank"]

I'm not sure if this is a bug, or just something that was never considered an issue. I assume the attribute (:name in this case) is overwriting the previous one, resulting in one error.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Referenced by

Pages