Hey,
 I found in the documentation about has_one
*":primary_key Specify the method that returns the primary key used for the 
association. By default this is id."*

My interpretation is that when I have a method in the model, I can point 
:foreign_key to this method

  has_one :participants_group, :class_name => 
"Group::Virtual::Participants",
          :foreign_key => :id,
          :primary_key => :participants_group_id,
          :dependent => :destroy,
          :inverse_of => :topic

private

def participant_group_id

# the result of this method should be taken as a foreign_key value in the 
query.

# IMHO Query should be: SELECT "groups".* FROM "groups" WHERE 
"groups"."type" IN ('Group::Virtual::Participants') AND "groups"."id" = 1 
LIMIT 1 

1

end

Instead the query is

SELECT "groups".* FROM "groups" WHERE "groups"."type" IN 
('Group::Virtual::Participants') AND "groups"."id"* IS NULL *LIMIT 1


In ActiveRecord::Associations::AssociationScope#add_constraints line 70 
there is

scope = scope.where(table[key].eq(*owner[foreign_key]*))

Which I think is wrong according to the documentation, because it just 
accesses attributes

To match the documentations iit shoud rather be 

scope = scope.where(table[key].eq(*owner.send foreign_key*))

Please tell me which should be true Documentation or Code, and please 
either change the line, or the documentation.


Thanks Martin.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to