Is there a way, in honeysql, to represent this?
...LEFT JOIN foo ON <http://bar.id|bar.id> = <http://foo.id|foo.id> AND bar.name = 'wibble'
I tried a few things, like nesting vectors in the honeysql (left-join
clause, but it no work, cap'tain!
(left-join :foo [:and [:= :<http://bar.id|bar.id> :<http://foo.id|foo.id>] [:= :bar.name "wibble"]])
should work I think?
I think I tried that, but reattempting
user=> (-> (select :* :bar) (left-join :foo [:and [:= :<http://foo.id|foo.id> :<http://bar.id|bar.id>] [:= :bar.name "wibble"]]) (h/format))
["SELECT *, bar LEFT JOIN foo ON (<http://foo.id|foo.id> = <http://bar.id|bar.id> AND bar.name = ?)" "wibble"]
no joy
ah, try if you have multiple left-joins
(left-join :foo [:and [:= :<http://bar.id|bar.id> :<http://foo.id|foo.id>] [:= :bar.name "wibble"]]
:a [:= <http://a.id|a.id> :<http://b.id|b.id>])
If you have multiple joins, you have to use the merge-
helpers
ah I see
user=> (-> (select :* :bar) (merge-left-join :foo [:and [:= :<http://foo.id|foo.id> :<http://bar.id|bar.id>] [:= :bar.name "wibble"]]) (merge-left-join :quux [:and [:= :<http://quux.id|quux.id> :<http://foo.id|foo.id>] [:= :foo.thing "wut"]]) (h/format))
["SELECT *, bar LEFT JOIN foo ON (<http://foo.id|foo.id> = <http://bar.id|bar.id> AND bar.name = ?) LEFT JOIN quux ON (<http://quux.id|quux.id> = <http://foo.id|foo.id> AND foo.thing = ?)" "wibble" "wut"]
Each left-join
/ merge-left-join
phrase only joins one table.
That's Sean! Using a series of (merge-left-join...)
solved it