updating join slot after inserting new data
"Ala'a (cmo-0)" <[email protected]>
| Newsgroups | gmane.lisp.clsql.general |
|---|---|
| Message-ID | <[email protected]> |
Hi,
I'm facing a problem with getting a join slot to return the latest set
of objects after inserting new ones.
I've sketched the following example to illustrate the problem I'm facing:
(clsql-sys:connect '("/home/alaa/sandbox/joins-test.sqlite3")
:database-type :sqlite3)
(clsql-sys:def-view-class school ()
((id :initarg :id :accessor id
:column "id" :type integer)
(name :initarg :name :accessor name
:column "name" :type string)
(teachers :reader teachers
:db-kind :join
:db-info (:join-class teacher
:home-key id :foreign-key school-id
:retrieval :deferred :set t))))
(clsql-sys:create-view-from-class 'school)
(clsql-sys:def-view-class teacher ()
((id :initarg :id :accessor id
:column "id" :type integer)
(name :initarg :name :accessor name
:column "name" :type string)
(school-id :initarg :school-id :accessor school-id
:column "school_id" :type integer)
(school :reader school
:db-kind :join
:db-info (:join-class school
:home-key school-id :foreign-key id
:retrieval :deferred :set nil))))
(clsql-sys:create-view-from-class 'teacher)
(setf *school* (make-instance 'school :id 1 :name "Lisp Land"))
(clsql-sys:update-records-from-instance *school*)
(setf *sam* (make-instance 'teacher :id 1 :name "Sam" :school-id 1))
(clsql-sys:update-records-from-instance *sam*)
(setf *mike* (make-instance 'teacher :id 2 :name "Mike" :school-id 1))
(clsql-sys:update-records-from-instance *mike*)
(teachers *school*) ; => returns two teachers
(setf *alan* (make-instance 'teacher :id 3 :name "Alan" :school-id 1))
(clsql-sys:update-records-from-instance *alan*)
(teachers *school*) ; => still returns two teachers, nothing about the
poor Alan.
(school *sam*) ; => returns a school object
(school *mike*) ; => returns a school object that is eq to the above
school object
(school *alan*) ; => return different object (in identity), but the same data
I've tried to set the teachers slot for the school to nil, hoping it
will retrieve the data
again from the database. but that didn't work.
regards,
Ala'a (cmo-0)