Commit f3da2e8e authored by ryszard.szopa's avatar ryszard.szopa
Browse files

save-dao bugfix

Problem: save-dao on a dao containing references to unsaved objects
would raise an error (revealed by new save-dao tests).

Fixed by editing slot-value-or-id-if-foreign to save any unsaved
daos. slot-value-or-id-if-foreign has also been moved to dao.lisp.

darcs-hash:e4f8d146738959360815fe72f77b422aea628360
parent dac03213
......@@ -38,6 +38,15 @@ exists in the database.")
(postmodern::query (:select (:exists (:select 1 :from (class-name-of dao) :where (:= 'id (get-id dao)))))
:single)))))
(defun slot-value-or-id-if-foreign (object slot)
"SLOT-VALUE if SLOT in OBJECT is not foreign, the ID of the object
in the slot otherwise. If the object is not saved, save it."
(let ((value (slot-value object slot)))
(cond ((and (typep value 'dao) (dao-exists-p value))
(get-id value))
((typep value 'dao) (get-id (save-dao value)))
(t value))))
(defun set-fields (object)
(iter (for field in (mapcar #'slot-definition-name (db-slots-of object)))
(appending `(,field ,(slot-value-or-id-if-foreign object field)))))
......
......@@ -19,11 +19,6 @@
"List of non-transient, instance allocated slots of OBJECT"
(remove-if #'non-db-slot (slots-of object)))
(defun slot-value-or-id-if-foreign (object slot)
"SLOT-VALUE if SLOT in OBJECT is not foreign, the ID of the object in the slot otherwise."
(let ((value (slot-value object slot)))
(or (and (typep value 'dao) (get-id value))
value)))
(defun with-connection-fun (connection-spec what-to-do)
"Functional interface to the macro WITH-CONNECTION."
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment