Created
September 24, 2009 14:29
-
-
Save flyerhzm/192759 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# To 2collegebums: This query generate a only one sql with left outer join, | |
# SELECT "comments"."id" AS t0_r0, "comments"."name" AS t0_r1, "comments"."post_id" AS t0_r2, "comments"."author_id" AS t0_r3, "base_users"."id" AS t1_r0, "base_users"."name" AS t1_r1, "base_users"."type" AS t1_r2, "posts"."id" AS t2_r0, "posts"."name" AS t2_r1, "posts"."category_id" AS t2_r2, "posts"."writer_id" AS t2_r3, "writers_posts"."id" AS t3_r0, "writers_posts"."name" AS t3_r1, "writers_posts"."type" AS t3_r2 FROM "comments" LEFT OUTER JOIN "base_users" ON "base_users".id = "comments".author_id LEFT OUTER JOIN "posts" ON "posts".id = "comments".post_id LEFT OUTER JOIN "base_users" writers_posts ON "writers_posts".id = "posts".writer_id AND ("writers_posts"."type" = 'Writer' ) WHERE (base_users.id = 1) | |
# so I think the test is not correct. | |
# | |
# this happens because it doesn't create an object association from post to writer | |
# by diving into the hash and creating those object associations | |
it "should detect preload of post => writer" do | |
comments = Comment.all(:include => [:author, {:post => :writer}], | |
:conditions => ["base_users.id = ?", BaseUser.first]).each do |com| | |
com.post.writer.name | |
end | |
Bullet::Association.should be_creating_object_association_for(comments.first, :author) | |
Bullet::Association.should be_creating_object_association_for(comments.first.post, :writer) | |
Bullet::Association.should_not be_detecting_unpreloaded_association_for(Post, :writer) | |
Bullet::Association.should be_completely_preloading_associations | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment