This project is archived and is in readonly mode.
named_scope buggy with has_many :through
-
Frederick Cheung
- Assigned user set to Frederick Cheung
- State changed from new to incomplete
I couldn't reproduce this with 2.1.2 or 2.2.2 or edge
I think you've skipped over a few steps. In the first bit you show a query selecting users.* going wrong but the corresponding bit of code you've shown you should be loading friendships, not users. Could your provide a more complete description of steps to reproduce ? (or even better, a failing test case)
-
Dennis Ushakov
Frederick, actually there's a bug in specification or in reflection code Spec says:
[:through]
Specifies a Join Model through which to perform the query. Options for :class_name and :foreign_key
are ignored, as the association uses the source reflection. You can only use a :through query through a belongs_to
or has_many association on the join model.
As we see here, :class_name should be ignored.
But in the source code we see: MacroReflection class in reflection.rb:
Returns the class name for the macro. For example, composed_of :balance, :class_name => 'Money' returns 'Money'
and has_many :clients returns 'Client'.
def class_name @class_name ||= options[:class_name] || derive_class_name end and no check for through attribute
-
Dennis Ushakov
Sorry for formatting issues. One addition. As I understand :source attribute should be used in this case, but it seems typo is dependent on this behaviour:
class Category < ActiveRecord::Base acts_as_list has_many :categorizationshas_many :articles,
:through => :categorizations, :order => "published_at DESC, created_at DESC"has_many :published_articles,
:through => :categorizations, :class_name => 'Article', :conditions => { :published => true }, :order => "published_at DESC" -
Prem Sichanugrist (sikachu)
- State changed from incomplete to resolved