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 = '[EMAIL PROTECTED]') 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 !
-- 
François Beausoleil
http://blog.teksol.info/
http://piston.rubyforge.org/

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to