If you attempt the create a has_many :through association that
uses a has_many association with nonstandard primary and foreign
keys, you will get an infinite loop when trying to use the
association.
This happens because the association calls owner_quoted_id in
construct_quoted_owner_attributes, and owner_quoted_id calls
quote_value. The problem is that quote_value is not defined on the
association itself and needs to be called through method_missing.
The method_missing implementation in association_collection tries
to send the method through to the reflection's class, but only
after calling construct_scope, and that method ends up calling
owner_quoted_id again, creating an infinite loop. The attached
patch against 2-3-stable implements the quote_value method on
AssociationCollection to send the call directly to the reflection's
class without going through method_missing.
Here is a code example:
class MailingList < ActiveRecord::Base
has_many :subscriptions
end
class Subscription < ActiveRecord::Base
belongs_to :mailing_list
belongs_to :user, :primary_key => :email, :foreign_key => :email
end
class User < ActiveRecord::Base
has_many :subscriptions, :primary_key => :email, :foreign_key => :email, :dependent => :destroy
has_many :mailing_lists, :through => :subscriptions, :primary_key => :email, :foreign_key => :email
end
User.first.mailing_lists => # infinite loop