Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Foreign table join not used if transform present #363

Open
rukor opened this issue Jul 30, 2016 · 2 comments
Open

Foreign table join not used if transform present #363

rukor opened this issue Jul 30, 2016 · 2 comments
Labels
inactive-issue? This issue should be closed within 2 weeks of the most recent comment due to inactivity

Comments

@rukor
Copy link

rukor commented Jul 30, 2016

If i have a transform in a foreign table then it doesnt include it in the joins for the query:

Lets say I have:

(defn update? [m k func]
  (if (m k)
    (update-in m [k] func)
    m))

(defentity table1
  (transform #(-> % (update? :description clob-to-string))))

(defentity table2
  (belongs-to table1 {:fk :table1-id}))

I get this:

(-> (k/select* d/table2)
    (k/fields :id)
    (k/with d/table1
            (k/fields :field2))
    (k/as-sql))
=> "SELECT \"table2\".\"id\" FROM \"table2\""

Whereas, if I remove the transform, I get

(-> (k/select* d/table2)
    (k/fields :id)
    (k/with d/table1
            (k/fields :field2))
    (k/as-sql))
=>
"SELECT \"table2\".\"id\", \"table1\".\"field2\" FROM \"table2\" LEFT JOIN \"table1\" ON \"table1\".\"id\" = \"table2\".\"table1-id\""
@immoh
Copy link
Member

immoh commented Jul 30, 2016

In order to be able to run the transform, two queries are executed:

(dry-run 
  (select table2 
          (fields :id)
          (with table1
                (fields :field2))))
dry run :: SELECT "table2"."id" FROM "table2" :: []
dry run :: SELECT "table1"."field2" FROM "table1" WHERE ("table1"."id" = ?) :: [1]
=> ({:id_2 1, :table1-id 1, :id 1})

@venantius
Copy link
Contributor

I'm going through old issues and trying to clean them up. Has this issue persisted?

If there hasn't been a response to this issue in 2 weeks, I'll close the ticket.

@venantius venantius added the inactive-issue? This issue should be closed within 2 weeks of the most recent comment due to inactivity label Feb 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
inactive-issue? This issue should be closed within 2 weeks of the most recent comment due to inactivity
Projects
None yet
Development

No branches or pull requests

3 participants