Object mapping

Mészáros Levente <[email protected]> Wed, 16 Nov 2005 11:34:54 +0100 (CET)
Newsgroups gmane.lisp.clsql.devel
Message-ID <[email protected]>
Hi,

 

Maybe I’m wrong about this, but shouldn’t clsql handle setting a slot 
value of a joined class (I mean setting a CLOS object as the value)? For 
example with the employee, company example when the company of 
an employe is set via (setf (slot-value ...)) the key should be updated in 
the employee and if db-auto-sync is on, then the database should also 
be updated. Moreover when setting the employees of a company, then 
the employee join-slots should be updated.

 

It seems to me that currenlty only the querying is supported by clsql.

 

Here is my version which is far from being complete, but it works for 
me. Could someone give me a hint that is this the correct way to do it 
or not? Maybe I could finalize this patch...

 

In ooddl.lisp:

 

(defmethod (setf slot-value-using-class) (new-value (class standard-db-
class)

                                                                            instance slot-def)

  (let* ((slot-name (%svuc-slot-name slot-def))

             (slot-object (%svuc-slot-object slot-def class))

             (slot-kind (view-class-slot-db-kind slot-object))

             (slot-info (view-class-slot-db-info slot-object)))

    (prog1

            (call-next-method)

      (when (and *db-auto-sync* 

                 (not *db-initializing*)

                 (not *db-deserializing*)

                 (eq slot-kind :join))

            (let ((home-key (gethash :home-key slot-info))

                  (foreign-key (gethash :foreign-key slot-info)))

              (if (gethash :set slot-info)

                  (mapcar (lambda (child)

                                    (setf (slot-value child foreign-key)

                                          (slot-value instance home-key))

                                    (update-record-from-slot child foreign-key)) new-
value)

                  (progn (setf (slot-value instance home-key)

                                       (slot-value new-value foreign-key))

                             (update-record-from-slot instance home-key))))))))

 

levy


______________________________________________________________________________________
A kötelező most kellemes! Megkötötte már? Tegye meg egyszerűen, kedvezményekkel az [origo] Biztosításon!
http://origo.hu/biztositas