Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is flat union chaining possible? Is it preferable to nested? #6

Open
bughit opened this issue Sep 24, 2015 · 3 comments
Open

Is flat union chaining possible? Is it preferable to nested? #6

bughit opened this issue Sep 24, 2015 · 3 comments

Comments

@bughit
Copy link

bughit commented Sep 24, 2015

[user_1.posts, user_2.posts, Post.published].inject(:union)
Nested
SELECT "posts".* FROM (
  SELECT "posts".* FROM (
    SELECT "posts".* FROM "posts"  WHERE "posts"."user_id" = 1
    UNION
    SELECT "posts".* FROM "posts"  WHERE "posts"."user_id" = 2
  ) posts
  UNION
  SELECT "posts".* FROM "posts"  WHERE (published_at < '2014-07-19 16:12:45.882648')
) posts
Flat
SELECT "posts".* FROM (
  SELECT "posts".* FROM "posts"  WHERE "posts"."user_id" = 1
  UNION
  SELECT "posts".* FROM "posts"  WHERE "posts"."user_id" = 2
  UNION
  SELECT "posts".* FROM "posts"  WHERE (published_at < '2014-07-19 16:12:45.882648')
) posts

Flat chaining strikes me as potentially less problematic at least for some engines than deep nesting. Is it possible to achieve that in the current version? Would it make sense to add this?

Something like: Relation.union(user_1.posts, user_2.posts, Post.published)

@bughit
Copy link
Author

bughit commented Sep 24, 2015

looks like #4 enables this, do you plan on merging it?

@bughit
Copy link
Author

bughit commented Oct 5, 2015

@brianhempel, what do you think of #4?

@brianhempel
Copy link
Owner

Flatness would be great, but it's not easily supported by AREL right now so until that's improved it's going to be hacktastic to get it to work reliably in this gem.

See also discussion on #4 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants