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

Sabra Crolleton sabra.crolleton at gmail.com
Fri Aug 28 05:21:39 UTC 2009


I was just going to display the fields in a record and my first thought was to use the relevant class and then just call get-dao and iterate over the slots, something like:

         (item (postmodern:get-dao 'countrynotes (parse-integer id))))

However, looking at the countrynotes definition, you quickly notice that it has a foreign key:

; shortened version of the countrynotes class
(defclass countrynotes ()
  (
   (id :accessor id :col-type int4 :initarg :id )
   (country-id :accessor country-id :col-type int4 :initarg :country-id :foreign-key (countries id))
   (name :accessor name :col-type varchar :initarg :name )
   (updated-at :accessor updated-at :col-type timestamp :initarg :updated-at ))
  (:metaclass postmodern:dao-class)
    (:table-name countrynotes)(:keys id))

In displaying the countrynote, I don't really want to show the country-id, I really want to display the name of the country instead, which is another table:
(defclass countries ()
  (
   (id :accessor id :col-type int4 :initarg :id )
   (name :accessor name :col-type varchar :initarg :name )
   (updated-at :accessor updated-at :col-type timestamp :initarg :updated-at ))
  (:metaclass postmodern:dao-class)
    (:table-name countries)(:keys id))

I can easily write out the full required sql statement, but is there a simple way of just using the dao?

Sabra




More information about the postmodern-devel mailing list