This project is archived and is in readonly mode.

#6673 new
Andriy Tyurnikov

Scoped uniqueness validation of associated objects

Reported by Andriy Tyurnikov | April 5th, 2011 @ 11:41 AM

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.

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

Pages