Attributes in many-to-many relations

107 views
Skip to first unread message

plamen...@gmail.com

unread,
Sep 30, 2013, 3:39:46 PM9/30/13
to sqlk...@googlegroups.com
Hello,

Let say we have an entity 'Employer'. Then an entity 'Employee'. Both are in a many-to-many relation over a table called 'Employment' (with additional fields and definitions which are unimportant for the case):

(defentity employer
  (many-to-many employee :employment)
  )

(defentity employe
  (many-to-many employer :employment)
  )

Now - the 'employment' relation has a validity period - the table's fields look more or less like that:
employee_fk int,
employer_fk int,
date_from date,
date_to date.

How can I use the date_from/date_to fields in Korma (any DML statements), for example to select the relation per specific date? Should I define an additional entity and how would look it's definition and how would change the definitions of 'employer' and 'employee'? Or is this unsupported? If yes - is there is a workaround which is better than going back to for a whole application back to clojure.tools.jdbc? (The question arises not only because of dates, but of all possible attributes attached to many-to-many relations which are often found in real db models).

Thank you in advance for any help!

Sam Raker

unread,
Jul 31, 2014, 3:07:13 PM7/31/14
to sqlk...@googlegroups.com
Bumping this, as I have basically the same question.

I'm also wondering whether I need to/can specify the many-to-many tables, e.g.,

(defentity user_to_tweet
    (database my-mys-db)
    (table :user_to_tweet)
    (pk :id)
    (entity-fields :is_mention))

Immo Heikkinen

unread,
Aug 12, 2014, 1:05:58 AM8/12/14
to sqlk...@googlegroups.com
Korma doesn't have support for attributes in many-to-many relations but as a workaround you could create an entity for the join table:

(defentity tweet)

(defentity user-to-tweet
  (belongs-to tweet {:fk :tweet_id}))

(defentity user
  (has-many user-to-tweet))

(select user (with user-to-tweet (with tweet)))



--
You received this message because you are subscribed to the Google Groups "Korma" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sqlkorma+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages