Created
April 2, 2013 05:46
-
-
Save moro/5290187 to your computer and use it in GitHub Desktop.
ummmm
This file contains hidden or 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
['foo', 'bar'].inject(Paste.scoped) {|rel, tag| | |
rel.where(id: Tagging.joins(:tag).select(:paste_id).where('tags.name = ?', tag)) | |
}.to_sql | |
# => | |
# SELECT "pastes".* | |
# FROM "pastes" | |
# WHERE "pastes"."id" IN (SELECT paste_id FROM "taggings" INNER JOIN "tags" ON "tags"."id" = "taggings"."tag_id" WHERE (tags.name = 'foo')) | |
# AND "pastes"."id" IN (SELECT paste_id FROM "taggings" INNER JOIN "tags" ON "tags"."id" = "taggings"."tag_id" WHERE (tags.name = 'bar')) | |
# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment