korma / Korma

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

sql-only not showing joins on "with" #258

Closed ricardojmendez closed 9 years ago

ricardojmendez commented 9 years ago

Suppose the following entity definition:

(declare users sessions)

(defentity users
       (has-many sessions {:fk :creator_id}))

(defentity sessions
       (table :sessions)
       (belongs-to users {:fk :creator_id}))

Executing:

(select users (with sessions))

will indeed return the users and sessions, however:

(sql-only (select users (with sessions))

will only return "SELECT \"users\".* FROM \"users\""

immoh commented 9 years ago

Subentities in with-many relation are fetched lazily using separate select statement for each main entity. sql-only returns only the select for main entity, dry-run shows also subentity selects:

(dry-run (select users (with sessions)))
dry run :: SELECT "users".* FROM "users" :: []
dry run :: SELECT "sessions".* FROM "sessions" WHERE ("sessions"."creator_id" = ?) :: [1]
=> ({:sessions [{:creator_id 1, :id 1}], :id 1})
ricardojmendez commented 9 years ago

Thanks, I guess we can close this as working as intended, but I'd suggest expanding the example documentation to note that.

immoh commented 9 years ago

PRs for the documentation welcome: https://github.com/korma/sqlkorma