X-Git-Url: http://git.kpe.io/?p=clsql.git;a=blobdiff_plain;f=sql%2Foodml.lisp;h=bb6f447d5841444bc0400e1a7675579b5d3d1a07;hp=b570cedcbb96d6aa8e6ac9b10012ae33e47d2f71;hb=5a1fe75645438f98da8bb8819f7858240df06e8e;hpb=80c2194145d2cd215dd94f2dc71afee14719c194 diff --git a/sql/oodml.lisp b/sql/oodml.lisp index b570ced..bb6f447 100644 --- a/sql/oodml.lisp +++ b/sql/oodml.lisp @@ -283,7 +283,7 @@ (setf pk (or pk (slot-value obj (slot-definition-name pk-slot)))))) (t - (insert-records :into (sql-expression :table view-class-table) + (insert-records :into (sql-expression :table view-class-table) :av-pairs record-values :database database) @@ -292,19 +292,26 @@ (not (null (view-class-slot-autoincrement-sequence pk-slot)))) (setf (slot-value obj (slot-definition-name pk-slot)) (database-last-auto-increment-id database - table + view-class-table pk-slot))))) - (setf pk (or pk - (slot-value - obj (slot-definition-name pk-slot))))) - (when (eql this-class nil) - (setf (slot-value obj 'view-database) database)))))) + (when pk-slot + (setf pk (or pk + (slot-value + obj (slot-definition-name pk-slot))))) + (when (eql this-class nil) + (setf (slot-value obj 'view-database) database))))))) ;; handle slots with defaults - (dolist (slot slots) - (when (and (slot-exists-p slot 'db-constraints) - (listp (view-class-slot-db-constraints slot)) - (member :default (view-class-slot-db-constraints slot))) - (update-slot-from-record obj (slot-definition-name slot)))) + (let* ((view-class (or this-class (class-of obj))) + (slots (if (normalizedp view-class) + (ordered-class-direct-slots view-class) + (ordered-class-slots view-class)))) + (dolist (slot slots) + (when (and (slot-exists-p slot 'db-constraints) + (listp (view-class-slot-db-constraints slot)) + (member :default (view-class-slot-db-constraints slot))) + (unless (and (slot-boundp obj (slot-definition-name slot)) + (slot-value obj (slot-definition-name slot))) + (update-slot-from-record obj (slot-definition-name slot)))))) pk))