korma / Korma

Tasty SQL for Clojure.
http://sqlkorma.com
1.47k stars 222 forks source link

When the target of a has-many is aliased, has-many breaks, but has-one still works #243

Closed zilti closed 10 years ago

zilti commented 10 years ago

What's the difference in how has-one and has-many work? I have a table trel_pers_name where the :alias is set, and I have a tdta_personen which refers to trel_pers_name using a has-many. Now with that has-many, and calling (select tdta_personen (with trel_pers_name)) Korma selects the first few trel_pers_name entries where the foreign key is NULL. As soon as I replace the has-many with a has-one, though, the result is perfectly fine - with the difference, of course, that I only get the first entry.

immoh commented 10 years ago

On the high level, has-one executes single query using JOIN and has-many queries children with a separate query. Have you looked at the generated SQL e.g. using dry-run?