From: Drew Crampsie Date: Fri, 28 Oct 2005 22:30:59 +0000 (-0700) Subject: fixed many-to-many X-Git-Url: https://git.hcoop.net/clinton/lisp-on-lines.git/commitdiff_plain/fce59b368550e32a6db608fb8e10f5e2f2e4f6ec fixed many-to-many darcs-hash:20051028223059-5417e-cd999b15827a0395b207c55cf2be95d18d725a3e.gz --- diff --git a/src/slot-presentations.lisp b/src/slot-presentations.lisp index 3757ee3..8bd517c 100644 --- a/src/slot-presentations.lisp +++ b/src/slot-presentations.lisp @@ -343,25 +343,63 @@ Calendar.setup({ (defslot-presentation many-to-many-slot-presentation (mewa-relation-slot-presentation) ((list-view :accessor list-view :initarg :list-view :initform :one-line) (action-view :accessor action-view :initarg :action-view :initform :viewer) - (create-view :initform :creator)) + (create-view :initform :creator) + (select-view :initform :as-string :accessor select-view)) (:type-name many-to-many) (:default-initargs :label "many to many")) -(defmethod present-slot ((slot many-to-many-slot-presentation) instance) - - (let ((instances (slot-value instance (slot-name slot)))) +(defun %delete-item (item) + (clsql:with-default-database (clsql:*default-database*) + (ignore-errors + (clsql:delete-instance-records item)))) + +(defaction delete-item ((self component) instance) + (multiple-value-bind (res err) (%delete-item instance) + (if (not err) + (call 'info-message :message "Removed Instance") + (call 'info-message :message (format nil "Could not remove item. Try removing associated items first. ~A" instance))))) + +(defaction delete-relationship ((slot many-to-many-slot-presentation) rel instance) + (delete-item (ucw::parent self) rel) + (sync-instance instance) + (answer-component (ucw::parent self) t)) + + +(defun find-many-to-many-join-class (slot instance) + (let* ((imd (getf (meta-model::find-slot-metadata instance (slot-name slot)) + :db-info)) + (jc (make-instance (getf imd :join-class))) + (jcmd (getf (meta-model::find-slot-metadata jc (getf imd :target-slot)) + :db-info))) + (getf jcmd :join-class))) + + + +(defmethod find-all-instances ((slot many-to-many-slot-presentation) instance) + (clsql:select (find-many-to-many-join-class slot instance) :flatp t)) + +(defmethod present-slot ((slot many-to-many-slot-presentation) instance) + (let ((instances (slot-value instance (slot-name slot))) + new-instance) (<:ul (<:li (