Hey,
I'm not sure if this is a bug or not. It certainly caught me off-guard.
class Bar < ActiveRecord::Base
belongs_to :foo
validates_uniqueness_of :something
end
class Foo < ActiveRecord::Base
has_many :bars
def boo(something)
bars.create!(:something => something)
end
def yay(something)
abar = bars.build(:something => something)
abar.save!
end
end
Foo.find(1).boo('oh dear')
Foo.find(2).boo('oh dear')
# those are both saved, no errors
Foo.find(1).yay('huzzah')
Foo.find(2).yay('huzzah') #=> fails, validates_uniqueness_of fires an
error.
The reason for the difference is that the find() issued by
validates_uniqueness_of is *scoped* to has_many(:bars) during the
call to bars.create!().
What does everyone think? Should validates_uniqueness_of ignore
with_scope() values when checking for conflicting records?
Thanks,
Trevor
--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-core?hl=en
-~----------~----~----~----~------~----~------~--~---