Hi all,
I have code like this:
class Contact < AR::B belongs_to :account_id has_many :email_addresses end
class EmailAddress < AR::B belongs_to :account belongs_to :party validates_uniquess_of :address, :scope => :account_id end
We use subdomain per account, and that's what account_id represents.
Now, if I create an EmailAddress in my tests, my validation rules are properly triggered. In my controller though, I can expose a failure. In the controller, here's how I do the create:
class ContactsController < AC def create @party = Party.create!(params[:party]) params[:email_address].each do |id, attrs| @party.email_addresses.create!(attrs) end end end
Creating a new contact with an existing E-Mail address works. The generated SQL to ensure validation is this:
SELECT * FROM email_addresses WHERE (contact_id = 41) AND (account_id = 17) AND (address = 'bob@test.com') LIMIT 1
Notice the contact scope ? This is obviously not right: the contact scope should not be taken into account when doing the validation.
Can anyone confirm / deny my problem ? I'm going to dive into AR's code tomorrow to expose the bug and attempt to correct it.
Thanks !