nah, its working by design, but you might not like it.  try these lines instead:

        del objectstore.uow().identity_map[Transition.mapper.instance_key(t1)]
        del objectstore.uow().identity_map[Place.mapper.instance_key(p2)]
        p2 = Place.mapper.get(p2.place_id)
        t1 = Transition.mapper.get(t1.transition_id)
        self.assert_result([t1], Transition, {'outputs': (Place, [{'name':'place3'}, {'name':'place1'}])})
        p2 = Place.eagermapper.get(p2.place_id)
        self.assert_result([p2], Place, {'inputs': (Transition, [{'name':'transition2'},{'name':'transition1'}])})

so heres the changes:

1. assert_result takes a list as the first argument since its normally used with the results of a select()
2. p2 is attached to transition1/transition2 as an "input" not an output in this test
3. the nature of the relationship here is such that transition1 gets associated with place2 by attaching a place2 to transition1.  however, that also means that transition1 is attached to place2.  But, since place2 was created in this same "transaction", all its attributes are already assumed to be loaded, and its not going to go and change around what youve set.  So, we force it to reload place2 altogether by removing it from the objectstore and reloading (and also transition1).  If you dont clear the objects out, the state that they received from the test suite before committing is incomplete, and the mapper doesnt try to guess which state needs to be filled in and which doesn't after a commit.

So #3 is really where this thing is going to get tricky for people.  Im probably going to have to add a lot more methods and configurations to the whole "objectstore" thing to give users greater control over what objects are loaded, what objects are not, easy ways to mark an object as "to be reloaded", etc.  This is why the docs for unitofwork are blank :).   its the simplest yet the hardest.  if you look at the docs and user comments for hibernate, youll see the same thing...a lot of complexity with regards to "object scope".  I am hoping this thing remains fairly simple compared to that.


On Dec 4, 2005, at 12:39 PM, Shuo Yang wrote:

Yea, there actually may be some funkiness in the many-to-many.

This patch adds couple assertions in the testCircular test case in manytomany.py, and it fails:

Index: manytomany.py
===================================================================
--- manytomany.py       (revision 690)
+++ manytomany.py       (working copy)
@@ -125,10 +125,11 @@
         p1.outputs.append(t1)

         objectstore.commit()
-
-
         l = Place.eagermapper.select()
         print repr(l)
+
+        self.assert_result(t1, Transition, {'outputs': (Place, [{'name':'place3'}])})
+        self.assert_result(p2, Place, {'outputs': (Transition, [{'name':'transition1'}])})

 if __name__ == "__main__":
     testbase.main()

Any ideas?



On 12/3/05, Robert Leftwich <[EMAIL PROTECTED]> wrote:
Shuo Yang wrote:
> So either have one class eagerly loaded and the other lazily loaded like
> this:
>
> Student.mapper = mapper(Student, studentTbl)
> Course.mapper = mapper(Course, courseTbl)
>
> Student.mapper.add_property('courses',
>          relation(Course.mapper, enrolTbl, lazy=True))
>
> Course.mapper.add_property('students',
>         relation(Student.mapper, enrolTbl, lazy=False))
>

I'm obviously having a bad day - I had read the eager loading emails and because
of that I set my relations up as being not eager loading - or so I thought. For
some reason I saw lazy=False and read it as eager=False! Apologies for that!!!

Anyway after making one of the relations lazy, I now have a slightly different
problem in that the objectstore is not being updated correctly, e.g after
setting up a student and a course and adding the course to the student, i.e.

s1.courses.append(c1)

print len(s1.courses)
print len(c1.students)

objectstore.commit()
#objectstore.clear()

s = Student.mapper.select()
c = Course.mapper.select()
print 'Courses', s[0].courses
print 'Students', c[0].students

If I leave the clear() commented out the results is:

1
0
Courses [<__main__.Course object at 0xb7382d8c>]
Students []

which is incorrect, but if I uncomment the clear() it is:

Courses [<__main__.Course object at 0xb72a4dcc>]
Students [<__main__.Student object at 0xb72a4f8c>]

as expected.

Note that it doesn't matter which relation I make lazy, but the behaviour is
reversed if I add the student to the course instead of the course to the student.

Robert



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Sqlalchemy-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users



--
---------------------------------------------------------------------------------------------------
John S. Yang

Reply via email to