raghubetina / cte-test

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Testing ActiveRecord::Cte

  1. bundle

  2. rails db:seed to create 4 posts, 3 of which have comments_count OR tags_count of more than 0.

  3. In rails console,

    Post.where.not(comments_count: ..0).
      or(Post.where.not(tags_count: ..0)).
      count

    correctly returns 3.

  4. The example from the documentation,

    Post.with(
      posts_with_comments: Post.where("comments_count > ?", 0),
      posts_with_tags: Post.where("tags_count > ?", 0)
    ).
    count

    incorrectly returns 4.

About


Languages

Language:Ruby 73.1%Language:HTML 14.1%Language:JavaScript 8.6%Language:SCSS 2.5%Language:CSS 1.7%