Skip to content

by-crate-id query bug #44

@jonathanstrong

Description

@jonathanstrong

https://github.com/mcorbin/meuse/blob/master/src/meuse/db/queries/category.clj#L27-L37

this code seems to return all categories, not just the categories associated with the crate.

I think the query needs to have the crate_id condition as part of the where clause, not as part of the left-join.

exapmle:

meuse=# select c.id, c.description, c.name, cc.crate_id
from categories c 
left join crates_categories cc on c.id=cc.category_id and cc.crate_id='2ff956f6-7b3e-49fc-8697-845d3a10fc75';

                  id                  |       description        |           name           |               crate_id               
--------------------------------------+--------------------------+--------------------------+--------------------------------------
 5527b5af-84ec-432f-b4a5-698048e5d096 | statistics               | statistics               | 2ff956f6-7b3e-49fc-8697-845d3a10fc75
 3759e640-2ba1-49c0-9ca3-10babdb07629 | science                  | science                  | 

"science" row should not be part of query results. if you change the second clause of the left-join to be in the where clause instead, it works without returning extra rows:

meuse=# select c.id, c.description, c.name, cc.crate_id
from categories c 
left join crates_categories cc on c.id=cc.category_id 
where cc.crate_id='2ff956f6-7b3e-49fc-8697-845d3a10fc75';

                  id                  |       description        |           name           |               crate_id               
--------------------------------------+--------------------------+--------------------------+--------------------------------------
 5527b5af-84ec-432f-b4a5-698048e5d096 | statistics               | statistics               | 2ff956f6-7b3e-49fc-8697-845d3a10fc75

fwiw I did try to fix this in the clojure code but failed :( - maybe next time.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions