Skip to content

Missing primary filter lifting to HAVING clause #690

@hrach

Description

@hrach
          I am a bit confused with separate WHERE and HAVING in some cases. For example these two produce identical query, which can't be right, as it only works with AND.
$this->model->books->findBy([
    ICollection::OR,
    ['title' => 'Book 1'],
    [CompareGreaterThanFunction::class, [CountAggregateFunction::class, 'tags->id'], 0],
]);
$this->model->books->findBy([
    ICollection::AND,
    ['title' => 'Book 1'],
    [CompareGreaterThanFunction::class, [CountAggregateFunction::class, 'tags->id'], 0],
]);
SELECT "books".* FROM "books" AS "books" 
LEFT JOIN "books_x_tags" AS "books_x_tags__COUNT" ON ("books"."id" = "books_x_tags__COUNT"."book_id") 
LEFT JOIN "tags" AS "tags__COUNT" ON ("books_x_tags__COUNT"."tag_id" = "tags__COUNT"."id") 
WHERE ((("books"."title" = 'Book 1'))) 
GROUP BY "books"."id", "books"."title" 
HAVING ((COUNT("tags__COUNT"."id") > 0));

Originally posted by @stepapo in #685 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions