diff options
author | Jon Leighton <j@jonathanleighton.com> | 2011-01-06 18:04:32 +0000 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-01-07 15:03:15 -0800 |
commit | 770e6893b9f2aaaebe3de10576931dc7194451bc (patch) | |
tree | a69337db0ed7743d302a9d54c142efa5447ab810 /activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb | |
parent | 441118458d57011ee1b1f1dcfea558de462c6da9 (diff) | |
download | rails-770e6893b9f2aaaebe3de10576931dc7194451bc.tar.gz rails-770e6893b9f2aaaebe3de10576931dc7194451bc.tar.bz2 rails-770e6893b9f2aaaebe3de10576931dc7194451bc.zip |
Construct an actual ActiveRecord::Relation object for the association scope, rather than a hash which is passed to apply_finder_options. This allows more flexibility in how the scope is created, for example because scope.where(a, b) and scope.where(a).where(b) mean different things.
Diffstat (limited to 'activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb')
-rw-r--r-- | activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb b/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb index b18ec23037..bc7894173d 100644 --- a/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb +++ b/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb @@ -88,14 +88,14 @@ module ActiveRecord super(join_table) end - def finder_options - super.merge( - :joins => construct_joins, - :readonly => ambiguous_select?(@reflection.options[:select]), - :select => @reflection.options[:select] || [ - @reflection.klass.arel_table[Arel.star], - join_table[Arel.star]] - ) + def association_scope + scope = super.joins(construct_joins) + scope = scope.readonly if ambiguous_select?(@reflection.options[:select]) + scope + end + + def select_value + super || [@reflection.klass.arel_table[Arel.star], join_table[Arel.star]] end # Join tables with additional columns on top of the two foreign keys must be considered |