X-Git-Url: https://git.hcoop.net/clinton/lisp-on-lines.git/blobdiff_plain/d2882889dc2234eef5882eeaa79e83e4e0d638a3..e1645f63189477f1b39a173a41fcbbfefb5e88a6:/src/relational-attributes.lisp diff --git a/src/relational-attributes.lisp b/src/relational-attributes.lisp index 5485515..58014f4 100644 --- a/src/relational-attributes.lisp +++ b/src/relational-attributes.lisp @@ -1,4 +1,81 @@ -(in-package :lol) +(in-package :lisp-on-lines) + +;;;; * Relational Attributes + + +;;;; ** has-a +;;;; Used for foreign keys, currently only works with clsql. + +(defattribute has-a () + () + (:default-properties + :has-a nil + :test 'meta-model::generic-equal)) + +;; +(define-layered-method attribute-value (object (attribute has-a)) + (meta-model:explode-foreign-key object (slot-name attribute) :nilp t)) + +(define-layered-method (setf attribute-value) ((value standard-object) object (attribute has-a)) + (let ((val (slot-value value (find-if (curry #'primary-key-p value) (list-keys value))))) + (setf (attribute-value object attribute) val))) + + + +(define-layered-function find-all-foreign-objects (o a)) + +(define-layered-method find-all-foreign-objects (object (attribute has-a)) + (select (meta-model:find-join-class object (slot-name attribute)) :flatp t)) + +(defdisplay ((attribute has-a) object) + (let ((args (plist-union (description.properties attribute) (has-a attribute))) + (val (attribute-value object attribute))) + (when val + (setf (getf args :type) + 'lol::one-line)) + (apply #'display* val + args))) + + +(defdisplay + :in-layer editor ((attribute has-a) object) + (