I tried multiple ways to get the with-column-writers macro in the repository to work and could not. I believe that the loop should read :in rather than :on as follows:
(defmacro with-column-writers ((&rest defs) &body body) `(let ((*custom-column-writers* (append (list ,@(loop :for (field writer) :in defs :collect `(cons (to-sql-name ,field) ,writer))) *custom-column-writers*))) ,@body))
With that in place, the following code works correctly:
(defclass foo () ((id :col-type int :initform :id :accessor foo-id) (stuff :initform :stuff :accessor foo-stuff)) (:metaclass postmodern:dao-class) (:keys id))
(setf foo (postmodern:with-column-writers ((:id #'(lambda (inst val) (setf (foo-id inst) val) (setf (foo-stuff inst) (format nil "My Value: ~A" val))))) (postmodern:get-dao 'foo 1)))
Hi Curtis,
It seems this has been broken ever since I introduced it. I actually had code that used it, but never noticed that also didn't work. How embarrassing.
The intent was for the arguments to be a plain list, not a list of lists, so there was a :by #'cddr missing from the loop. I've pushed a fix. if you change your code like this, it should work:
(setf foo (postmodern:with-column-writers (:id #'(lambda (inst val) (setf (foo-id inst) val) (setf (foo-stuff inst) (format nil "My Value: ~A" val)))) (postmodern:get-dao 'foo 1)))
Let me know if you have any more problems.
Best, Marijn
postmodern-devel@common-lisp.net