Skip to content

Commit

Permalink
nested object predicate support for 1-n & m-n relationship [GH-33]
Browse files Browse the repository at this point in the history
  • Loading branch information
tamizhvendan committed May 1, 2020
1 parent b10c24f commit 655529c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
23 changes: 17 additions & 6 deletions src/honeyeql/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@
(let [{:attr.column.ref.associative/keys [left-ident right-ident]} join-attr-md]
[:and
[:=
(keyword (str (:self alias) "." (heql-md/attr-column-name heql-meta-data left)))
(keyword (str (:parent alias) "." (heql-md/attr-column-name heql-meta-data left)))
(keyword (str assoc-table-alias "." (heql-md/attr-column-name heql-meta-data left-ident)))]
[:=
(keyword (str assoc-table-alias "." (heql-md/attr-column-name heql-meta-data right-ident)))
(keyword (str (:parent alias) "." (heql-md/attr-column-name heql-meta-data right)))]]))
(keyword (str (:self alias) "." (heql-md/attr-column-name heql-meta-data right)))]]))

(defmulti eql->hsql (fn [db-adapter heql-meta-data eql-node] (find-join-type heql-meta-data eql-node)))

Expand Down Expand Up @@ -98,11 +98,22 @@
(let [heql-meta-data (:heql-meta-data db-adapter)
join-attr-md (heql-md/attr-meta-data heql-meta-data join-attr-ident)
ref-type (:attr.column.ref/type join-attr-md)
alias {:self self-alias
:parent (get-in eql-node [:alias :self])}]
alias {:self self-alias
:parent (get-in eql-node [:alias :self])}
from-relation-ident (heql-md/entity-relation-ident heql-meta-data (:attr.column.ref/right join-attr-md))
from-clause [from-relation-ident (keyword self-alias)]]
(case ref-type
:attr.column.ref.type/one-to-one [[[(heql-md/entity-relation-ident heql-meta-data (:attr.column.ref/right join-attr-md)) (keyword self-alias)]]
(one-to-one-join-predicate heql-meta-data join-attr-md alias)])))
:attr.column.ref.type/one-to-one [[from-clause]
(one-to-one-join-predicate heql-meta-data join-attr-md alias)]
:attr.column.ref.type/one-to-many [[from-clause]
(one-to-many-join-predicate heql-meta-data join-attr-md alias)]
:attr.column.ref.type/many-to-many (let [assoc-table-alias (str (gensym))
assoc-table-from-clause [(->> (:attr.column.ref.associative/ident join-attr-md)
(heql-md/entity-meta-data heql-meta-data)
:entity.relation/ident)
(keyword assoc-table-alias)]]
[[from-clause assoc-table-from-clause]
(many-to-many-join-predicate heql-meta-data join-attr-md alias assoc-table-alias)]))))

#_ n
#_ (hsql-join-predicate db n :payment/customer)
Expand Down
16 changes: 8 additions & 8 deletions src/honeyeql/meta_data.clj
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,11 @@
:attr.ref/type left-entity-ident
:attr.entity/ident left-entity-ident
:attr.column.ref/type :attr.column.ref.type/many-to-many
:attr.column.ref/left ref-attr
:attr.column.ref/left r-ref-attr
:attr.column.ref.associative/ident entity-ident
:attr.column.ref.associative/left-ident self-attr
:attr.column.ref.associative/right-ident r-self-attr
:attr.column.ref/right r-ref-attr})
:attr.column.ref.associative/left-ident r-self-attr
:attr.column.ref.associative/right-ident self-attr
:attr.column.ref/right ref-attr})
(assoc-in [:attributes many-to-many-rev-attr-ident]
{:attr/ident many-to-many-rev-attr-ident
:attr.ident/camel-case (attribute-ident-in-camel-case many-to-many-rev-attr-ident)
Expand All @@ -287,11 +287,11 @@
:attr.ref/type right-entity-ident
:attr.entity/ident right-entity-ident
:attr.column.ref/type :attr.column.ref.type/many-to-many
:attr.column.ref/left r-ref-attr
:attr.column.ref/left ref-attr
:attr.column.ref.associative/ident entity-ident
:attr.column.ref.associative/left-ident r-self-attr
:attr.column.ref.associative/right-ident self-attr
:attr.column.ref/right ref-attr})
:attr.column.ref.associative/left-ident self-attr
:attr.column.ref.associative/right-ident r-self-attr
:attr.column.ref/right r-ref-attr})
(update-in [:entities left-entity-ident :entity/req-attrs]
conj many-to-many-rev-attr-ident)
(update-in [:entities right-entity-ident :entity/req-attrs]
Expand Down

0 comments on commit 655529c

Please sign in to comment.