[postmodern-devel] Using get-dao to somehow pull in foreign key linked fields?

Marijn Haverbeke marijnh at gmail.com
Fri Aug 28 06:34:19 UTC 2009


Hi Sabra,

There's no elegant provision for implicitly joining things onto DAO
objects, but there is a hack. See
http://common-lisp.net/project/postmodern/postmodern.html#with-column-writers
. Here's the only that I ever made of it (as far as I know, it's the
only use ever made of it at all), with some names replaced to protect
all the trade secrets that are obviously present in such a thing:

(defun get-foos-by (condition)
  (with-column-writers ('actives 'has-active-bars 'shape 'shape)
    (query-dao 'foo-desc
      (:select 'foo.* (:as 'shape.name 'shape)
              (:as (:exists (:select 1 :from 'bar :where (:and (:=
'foo-id 'foo.id) 'active))) 'actives)
        :from 'foo :left-join 'shape :on (:= 'shape.id 'foo.shape-id)
        :where (:raw condition)))))

Hope that helps,
Marijn




More information about the postmodern-devel mailing list