[elephant-devel] Learning about Elephant

John develgenius at gmail.com
Wed Jan 28 16:19:26 UTC 2009


Hi Ian,

I guess there is nothing better than trying it out :)

ELE-TESTS> (defpclass person ()
             ((friends :accessor friends-of :associate (person friends)
:many-to-many t)))
#<PERSISTENT-METACLASS PERSON>
ELE-TESTS> (defparameter person1 (make-instance 'person))
PERSON1
ELE-TESTS> (defparameter person2 (make-instance 'person))
PERSON2
ELE-TESTS> (defparameter person3 (make-instance 'person))
PERSON3
ELE-TESTS> (defparameter person4 (make-instance 'person))
PERSON4
ELE-TESTS> (defparameter person5 (make-instance 'person))
PERSON5
ELE-TESTS> (setf (friends-of person1) person2)
#<PERSON oid:3>
ELE-TESTS> (setf (friends-of person1) person3)
#<PERSON oid:4>
ELE-TESTS> (setf (friends-of person1) person4)
#<PERSON oid:5>
ELE-TESTS> (setf (friends-of person1) person5)
#<PERSON oid:6>
ELE-TESTS> (setf (friends-of person2) person3)
#<PERSON oid:4>
ELE-TESTS> (friends-of person1)
(#<PERSON oid:3> #<PERSON oid:4> #<PERSON oid:5> #<PERSON oid:6>)
ELE-TESTS> (friends-of person2)
(#<PERSON oid:2> #<PERSON oid:4>)
ELE-TESTS> (friends-of person3)
(#<PERSON oid:2> #<PERSON oid:3>)
ELE-TESTS> (friends-of person4)
(#<PERSON oid:2>)
ELE-TESTS> (friends-of person5)
(#<PERSON oid:2>)
ELE-TESTS> (remove-association person1 'friends person2)
NIL
ELE-TESTS> (friends-of person1)
(#<PERSON oid:4> #<PERSON oid:5> #<PERSON oid:6>)

So, it does seem to behave as I suspected.

Now, I think the last few questions I have on this subject before delving
further are

1) What data structure do associations use to store the list of associated
objects? My little understanding of update-association-end implies that the
association slot creates some sort of indexed-btree.

2) Are they storing a reference to the objects themselves or just the OIDs.
It seems to me that it stores a reference on that "indexed-btree". However,
this (setf (get-value (oid target) index) (oid instance)) in
update-association-end seems to imply that it stores the key/value using the
OID.

3) Can the list be indexed in any way or do we basically need to "manually"
sort it to our liking once we retrieve the associations. If my assumptions
above are correct, the associations are indexed based on OID sequence.

As a general question in reference to #2 above, does Elephant always use the
OIDs to store references of objects? I read on the list that a while back
someone (I think it was you) posted something along the lines that we
shouldn't use OIDs as unique identifiers because OIDs could change. I
suppose during migrations, when objects are re-created, the OIDs change. Is
that correct? Do the migrations take care of updating all these OID
references?

Now, a separate modeling question arises :) Imagine a many-to-many
relationship where the relationship needs to store additional information.
For example, imagine a membership club. Person1 becomes a member of Club1 on
1/1/09 and is paid thru 3/31/09. We have a class for person and a class for
club, but when we store the association between the two, we would like to
store the "effective-date" and the "termination-date" of the membership
(association). How would you approach that?

Thanks again,
JD

On Wed, Jan 28, 2009 at 12:32 AM, Ian Eslick <eslick at media.mit.edu> wrote:

> That would be correct if you added (setf (friends-of person3) person2)
>
> On Jan 27, 2009, at 5:06 PM, John wrote:
>
> > Thanks for the clear example. However, maybe the idioms are
> > confusing me, but many-to-many tells me that I should be able to do
> > something like:
> >
> > (setf (friends-of person1) person2)
> > (setf (friends-of person1) person3)
> > (setf (friends-of person1) person4)
> > (setf (friends-of person1) person5)
> >
> > (setf (friends-of person2) person3)
> >
> > such that:
> >
> > (friends-of person1) => (person2 person3 person4 person5)
> > (friends-of person2) => (person1 person3)
> > (friends-of person3) => (person1 person2)
> > (friends-of person4) => person1
> > (friends-of person5) => person1
> >
> > Would that be the expected behavior?
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/elephant-devel/attachments/20090128/acc7a06a/attachment.html>


More information about the elephant-devel mailing list