korma / Korma

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

Korma 0.5.0-RC1 breaks "with" on many-to-many relationships #400

Open AlexAti opened 5 years ago

AlexAti commented 5 years ago

With this definitions:

(defentity user
  (table :users)
  (pk :userid)
  (entity-fields :userid)
  (many-to-many role :user_roles {:lfk :userid
                                  :rfk :roleid})
  (has-many answer {:fk :userid}))

(defentity role
  (table :role)
  (pk :roleid)
  (entity-fields :roleid))

The following works with korma 0.4.3 but not with korma 0.5.0-RC1:

(select user (with role))

Also, the output of (dry-run (select user (with role))) provides the following in 0.4.3:

dry run :: SELECT "users"."userid" FROM "users" :: []
dry run :: SELECT "role"."roleid" FROM "role" INNER JOIN "user_roles" ON "user_roles"."roleid" = "role"."roleid" WHERE ("user_roles"."userid" = ?) :: [1]
=> ({:userid 1, :role [{:roleid 1}]})

but the following in 0.5.0-RC1:

dry run :: SELECT "users"."userid" FROM "users" :: []
dry run :: SELECT "role"."roleid" FROM "role" INNER JOIN "user_roles" ON () :: []
=> ({:userid 1, :role [{:roleid 1}]})

So the issue seems with how the following part is being handled:

(many-to-many role :user_roles {:lfk :userid
                                :rfk :roleid})

I haven't found anything more concrete unfortunately.

Freid001 commented 3 years ago

+1