From 655529cfe0cac4b44ce8611cc09921979f1128e8 Mon Sep 17 00:00:00 2001 From: Tamizhvendan S Date: Fri, 1 May 2020 16:45:10 +0530 Subject: [PATCH] nested object predicate support for 1-n & m-n relationship [GH-33] --- src/honeyeql/core.clj | 23 +++++++++++++++++------ src/honeyeql/meta_data.clj | 16 ++++++++-------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/honeyeql/core.clj b/src/honeyeql/core.clj index 52a81aa..8e08288 100644 --- a/src/honeyeql/core.clj +++ b/src/honeyeql/core.clj @@ -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))) @@ -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) diff --git a/src/honeyeql/meta_data.clj b/src/honeyeql/meta_data.clj index f9132bc..9fc0d36 100644 --- a/src/honeyeql/meta_data.clj +++ b/src/honeyeql/meta_data.clj @@ -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) @@ -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]