With being ignored by korma (clojure)

186 Views Asked by At

I have the following code:

(defentity users
  (database korma-db)
  (has-many tags))

(defentity tags
  (database korma-db)
  (belongs-to users))

(-> (select* users)
    (with tags)
    (fields :address)
    (where {:id 1})
    (as-sql))

and it generates the following sql:

SELECT "users"."address" FROM "users" WHERE ("users"."id" = ?)

While I would expect it to include a join to the tags table, by merit of having the with macro applied. Clearly this isn't the case, but executing it will produce an empty :tags key in the single returned record.

Am I missing something here?

1

There are 1 best solutions below

0
Nico Balestra On

did you create the actual referential constraint on the database? I think I had the same issue once and I fixed it by creating a foreign key when defining the field. i.e. in PostgreSQL

CREATE TABLE tags (
...
 users_id INTEGER REFERENCES users(id),
)