Rework initialize-instance for view-class-direct-slot-definition
authorKevin Rosenberg <kevin@rosenberg.net>
Fri, 4 Sep 2009 18:51:23 +0000 (12:51 -0600)
committerKevin Rosenberg <kevin@rosenberg.net>
Fri, 4 Sep 2009 18:51:23 +0000 (12:51 -0600)
ChangeLog
sql/metaclasses.lisp

index 714604db46918525b79eb1df99e8ab2956d647c1..762dd4b7f6d8c07042f4a627fd2188c8ccb4af2a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -16,6 +16,8 @@
        (thanks to Stephen Compall)
        * sql/database.lisp: Use :verbose nil for asdf:operate
        invocation (Thanks to Mackram Raydan)
+       * sql/metaclasses.lisp: Rework initialize-instance for
+       view-class-direct-slot-definition (thanks to Stephen Compall)
 
 31 Aug 2009  Kevin Rosenberg <kevin@rosenberg.net>
        * sql/db-interface.lisp: Fix spelling error (thanks to
index 2a0b4b9b2c835c30f194c46674b4c2fe795e65b0..a9e3ccd84efe2290fdd74e1f705e203981472634 100644 (file)
@@ -1,8 +1,6 @@
 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
 ;;;; *************************************************************************
 ;;;;
-;;;; $Id$
-;;;;
 ;;;; CLSQL metaclass for standard-db-objects created in the OODDL.
 ;;;;
 ;;;; This file is part of CLSQL.
@@ -427,29 +425,17 @@ implementations."
       (car list)
       list))
 
-(defmethod initialize-instance :around ((obj view-class-direct-slot-definition)
-                                        &rest initargs)
-  (do* ((parsed (list obj))
-        (name (first initargs) (first initargs))
-        (val (second initargs) (second initargs))
-        (type nil)
-        (db-constraints nil))
-      ((null initargs)
-       (setq parsed
-             (append parsed
-                     (list 'specified-type type
-                           :type (compute-lisp-type-from-specified-type
-                                  type db-constraints))))
-       (apply #'call-next-method parsed))
-    (case name
-      (:db-constraints
-       (setq db-constraints val)
-       (setq parsed (append parsed (list name val))))
-      (:type
-       (setq type val))
-      (t
-       (setq parsed (append parsed (list name val)))))
-    (setq initargs (cddr initargs))))
+(defmethod initialize-instance :around
+    ((obj view-class-direct-slot-definition)
+     &rest initargs &key db-constraints db-kind type &allow-other-keys)
+  (when (and (not db-kind) (member :primary-key (listify db-constraints)))
+    (warn "Slot ~S constrained to be :primary-key, but not marked as :db-kind :key"
+          (slot-definition-name obj)))
+  (apply #'call-next-method obj
+         'specified-type type
+         :type (compute-lisp-type-from-specified-type
+                type db-constraints)
+         initargs))
 
 (defmethod compute-effective-slot-definition ((class standard-db-class)
                                               #+kmr-normal-cesd slot-name