korma / Korma

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

multiple belongs-to same entity #281

Closed not3 closed 6 years ago

not3 commented 9 years ago
(defentity users)
(defentity posts
  (belongs-to users :author_id)
  (belongs-to users :created_by)
  (belongs-to users :updated_by))
table posts
title markdown author_id created_by updated_by

How to deal with multiple relationships with these entities

immoh commented 9 years ago

It is not currently supported by Korma. You can work around by defining a separate entity for each relation, and point them all to users table.

venantius commented 6 years ago

This issue has been brought up in other issues on this project and is therefore a duplicate. TL;DR - you can follow the advice above or map the relationship explicitly in the query using joins.