LauJensen / clojureql

ClojureQL is superior SQL integration for Clojure
https://clojureql.sabrecms.com
Eclipse Public License 1.0
285 stars 39 forks source link

aliases in projections of joined tables incorrectly results in subselect #31

Closed mclark closed 13 years ago

mclark commented 13 years ago

when joining two projected tables with no aliases, the resulting query is as expected:

(compile (-> (table db :table1)
    (join
     (project (table db :table2) [:id])
     (where (= :table1.table2_id :table2.id)))) nil)

["SELECT table1.*,table2.id FROM table1 JOIN table2 ON (table1.table2_id = table2.id)"]

however, when aliases are introduced in the second table, a subselect is created.

(compile (-> (table db :table1)
    (join
     (project (table db :table2) [[:id :as :table2id]])
     (where (= :table1.table2_id :table2.id)))) nil)

["SELECT table1.*,table2_subselect.table2id FROM table1 JOIN (SELECT table2.id AS table2id FROM table2) AS table2_subselect ON (table1.table2_subselect_id = table2_subselect.id)"]

I would have expected the output to be:

["SELECT table1.*,table2.id AS table2id FROM table1 JOIN table2 ON (table1.table2_id = table2.id)]

This issue was noted in the latest SNAPSHOT build.

bendlas commented 13 years ago

That's part of the issue I have been seeing https://github.com/LauJensen/clojureql/issues#issue/29

mclark commented 13 years ago

This has been resolved