(labels ((sym->sql (sym) (string-downcase (substitute #\_ #\- (string sym))))
(get-def (slot) (caar (query
(format nil "SELECT DISTINCT adsrc from pg_attrdef join pg_attribute on attnum = adnum where adrelid = (select oid from pg_class where relname = '~A') and attname = '~A'" (sym->sql (class-name (class-of view))) (sym->sql slot)))))
- (get-default-value (slot) (caar (query (format nil "SELECT ~A" (get-def slot))))))
+ (get-default-value (slot)
+ (let ((def (get-def slot)))
+ (if def
+ (caar (query (format nil "SELECT ~A" def)))
+ (error "No default value for primary key : ~A" slot)))))
(dolist (slot (list-slots view))
(when (and (primary-key-p view slot)
(equal (slot-value view slot) nil)))
(setf (slot-value view slot) (get-default-value slot)))))
(update-records-from-instance view :database database)
- (update-instance-from-records view :database database))
+ (update-instance-from-records view :database database)
+ (update-objects-joins (list view)))
"returns the SLOT in the foreign VIEW-CLASS that joins with FOREIGN-KEY"
(car (list-relations-helper view (find-join-helper foreign-key) :return-key :foreign-key)))
+(defmethod explode-has-many ((view t) join-slot)
+ "returns the class of the join as the primary value, the second and third value is the home key and the foreign key"
+ (let ((att (assoc join-slot (list-join-attributes view))))
+ (values (getf (cdr att) :join-class)
+ (getf (cdr att) :home-key)
+ (getf (cdr att) :foreign-key))))
+
+
(defmethod default-attributes ((model t))
+ "return the default attributes for a given model using the meta-model's meta-data"
(append (mapcar #'(lambda (s)
(cons (car s)
(gen-pslot