GithubHelp home page GithubHelp logo

Comments (1)

brianhempel avatar brianhempel commented on July 19, 2024

From the example in your README:

current_user.posts.union(Post.published,true)
SELECT "posts".* FROM (
  SELECT "posts".* FROM "posts"  WHERE "posts"."user_id" = ?
  UNION
  SELECT "posts".* FROM "posts"  WHERE (published_at < '2014-07-19 16:04:21.918366')
) posts_union, posts

…you are selecting "posts".* from posts_union, posts, which if loaded into ActiveRecord would actually load every single post, not the union result. You would want to SELECT "posts_union".* to load the records from the union. However, if you SELECT "posts_union".*, then any .where() calls will filter "posts", which we don't want.

current_user.posts.union(Post.published,true).where(public: true)
SELECT "posts_union".* FROM (
  SELECT "posts".* FROM "posts"  WHERE "posts"."user_id" = ?
  UNION
  SELECT "posts".* FROM "posts"  WHERE (published_at < '2014-07-19 16:04:21.918366')
) posts_union, posts WHERE "posts"."public" = 't'

…we'd probably want WHERE "posts_union"."public" = 't' instead of WHERE "posts"."public" = 't'.

Maybe something like SELECT "posts".* FROM posts AS original_posts, (union stuff) posts

In any case, the whole thing is a CROSS JOIN which weirds me out. Why do you need a CROSS JOIN?

I'm not sure this is a problem that ActiveRecordUnion should support. Can you provide a full example of what kind of aggregation you are trying to do?

from active_record_union.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.