Hi, I'm working with two models that have a "has_and_belongs_to_many" relation. Both models reside on a database that it is not the default one.
A < External has_and_belongs_to_many: B
B < External has_and_belongs_to_many: A
Retriving the information for A works perfectly, but when trying to "create" an element on A:
"A.B.create(...)"
ActiveRecord tries to create it on the default database. The solution was doing:
b = B.find(...) A.B << b
But, looking on the sourcecode I've found on the ActiveRecord file "has_and_belongs_to_many_association.rb [25:29]"
def has_primary_key? return @has_primary_key unless @has_primary_key.nil? @has_primary_key = (ActiveRecord::Base.connection.supports_primary_key? && ActiveRecord::Base.connection.primary_key(@reflection.options [:join_table])) end
Shouln't it be something like?
def has_primary_key? return @has_primary_key unless @has_primary_key.nil? @has_primary_key = (@owner.connection.supports_primary_key? && @owner.connection.primary_key(@reflection.options [:join_table])) end
Thank you