Scoped uniqueness validation of associated objects #999

Closed
lighthouse-import opened this Issue May 16, 2011 · 1 comment

Comments

Projects
None yet
1 participant
@lighthouse-import

Imported from Lighthouse. Original ticket at: http://rails.lighthouseapp.com/projects/8994/tickets/6673
Created by Andriy Tyurnikov - 2011-04-05 10:41:54 UTC

class Poll < ActiveRecord::Base
has_many :answers

validates_associated :answers

accepts_nested_attributes_for :answers, :allow_destroy => true
end

class Answer < ActiveRecord::Base
belongs_to :poll

validates_uniqueness_of :body, :scope => :poll_id
end

When new poll is created,
attributes for associated answers are passed,
but uniqueness of answers body in scope of poll is not validated.

Any ideas how to fix that.

@lighthouse-import

This comment has been minimized.

Show comment
Hide comment
@lighthouse-import

lighthouse-import May 16, 2011

Imported from Lighthouse.
Comment by Kane - 2011-04-05 23:38:33 UTC

can you supply a failing test case?

Imported from Lighthouse.
Comment by Kane - 2011-04-05 23:38:33 UTC

can you supply a failing test case?

hisas pushed a commit to hisas/rails that referenced this issue May 9, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment