kwrooijen / gungnir

A fully featured, data-driven database library for Clojure.

Home Page:https://kwrooijen.github.io/gungnir/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support linked relations

kwrooijen opened this issue · comments

Currently relations are linked directly. That doesn't work well for the following use case:

user
---
id : uuid
user_organization
---
id : uuid
user_id : foreign key user(id)
organization_id : foreign key organization(id)
organization
---
id : uuid

In this case, users are linked to organizations through the user_organization table. We need to somehow resolve a user / organization relations through user_organization.

Possibly something along the lines of:

;; User model
[:map 
 {:has-many {:organization {:field :user/organizations, :through :user_organization/organization_id}}
 ,,,
 }]

;; Organizatin model
[:map 
 {:has-many {:user {:field :organization/users, :through :user_organization/user_id}}
 ,,,
 }]