Created
March 25, 2011 23:36
-
-
Save nathansobo/887854 to your computer and use it in GitHub Desktop.
A join to a union, which produces a subquery
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
(Blog.where(:user_id => 1) | Blog.where(:public => true)).join(Post).to_sql.should be_like_query(%{ | |
select t1.id as t1__id, | |
t1.user_id as t1__user_id, | |
t1.public as t1__public, | |
posts.id as posts__id, | |
posts.blog_id as posts__blog_id | |
from ((select * | |
from blogs | |
where blogs.user_id = :v1) | |
union | |
(select * | |
from blogs | |
where blogs.public = :v2)) as t1 | |
inner join posts | |
on t1.id = posts.blog_id | |
}, :v1 => 1, :v2 => true) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment