I have code like this:
class Contact < AR::B
class EmailAddress < AR::B
validates_uniquess_of :address, :scope => :account_id
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
@party = Party.create!(params[:party])
params[:email_address].each do |id, attrs|
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 = 'firstname.lastname@example.org') 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.