Make dynamic finders respect the :include on HasManyThrough associations. Closes #10998. [cpytel]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8890 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
23e58a0552
commit
f2546164d6
@ -1,5 +1,7 @@
|
||||
*SVN*
|
||||
|
||||
* Make dynamic finders respect the :include on HasManyThrough associations. #10998. [cpytel]
|
||||
|
||||
* Base#instantiate_time_object only uses Time.zone when Base.time_zone_aware_attributes is true; leverages Time#time_with_datetime_fallback for readability [Geoff Buesing]
|
||||
|
||||
* Refactor ConnectionAdapters::Column.new_time: leverage DateTime failover behavior of Time#time_with_datetime_fallback [Geoff Buesing]
|
||||
|
@ -236,6 +236,7 @@ def construct_scope
|
||||
:find => { :from => construct_from,
|
||||
:conditions => construct_conditions,
|
||||
:joins => construct_joins,
|
||||
:include => @reflection.options[:include],
|
||||
:select => construct_select,
|
||||
:order => @reflection.options[:order],
|
||||
:limit => @reflection.options[:limit] } }
|
||||
|
@ -246,6 +246,12 @@ def test_eager_count_performed_on_a_has_many_association_with_multi_table_condit
|
||||
author_posts_without_comments = author.posts.select { |post| post.comments.blank? }
|
||||
assert_equal author_posts_without_comments.size, author.posts.count(:all, :include => :comments, :conditions => 'comments.id is null')
|
||||
end
|
||||
|
||||
def test_eager_count_performed_on_a_has_many_through_association_with_multi_table_conditional
|
||||
person = people(:michael)
|
||||
person_posts_without_comments = person.posts.select { |post| post.comments.blank? }
|
||||
assert_equal person_posts_without_comments.size, person.posts_with_no_comments.count
|
||||
end
|
||||
|
||||
def test_eager_with_has_and_belongs_to_many_and_limit
|
||||
posts = Post.find(:all, :include => :categories, :order => "posts.id", :limit => 3)
|
||||
|
5
activerecord/test/fixtures/readers.yml
vendored
5
activerecord/test/fixtures/readers.yml
vendored
@ -2,3 +2,8 @@ michael_welcome:
|
||||
id: 1
|
||||
post_id: 1
|
||||
person_id: 1
|
||||
|
||||
michael_authorless:
|
||||
id: 2
|
||||
post_id: 3
|
||||
person_id: 1
|
@ -1,4 +1,5 @@
|
||||
class Person < ActiveRecord::Base
|
||||
has_many :readers
|
||||
has_many :posts, :through => :readers
|
||||
has_many :posts_with_no_comments, :through => :readers, :source => :post, :include => :comments, :conditions => 'comments.id is null'
|
||||
end
|
||||
|
@ -25,7 +25,7 @@ def find_most_recent
|
||||
has_and_belongs_to_many :special_categories, :join_table => "categories_posts", :association_foreign_key => 'category_id'
|
||||
|
||||
has_many :taggings, :as => :taggable
|
||||
has_many :tags, :through => :taggings, :include => :tagging do
|
||||
has_many :tags, :through => :taggings do
|
||||
def add_joins_and_select
|
||||
find :all, :select => 'tags.*, authors.id as author_id', :include => false,
|
||||
:joins => 'left outer join posts on taggings.taggable_id = posts.id left outer join authors on posts.author_id = authors.id'
|
||||
|
Loading…
Reference in New Issue
Block a user