]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
(no commit message)
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 11 Sep 2005 00:19:20 +0000 (00:19 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 11 Sep 2005 00:19:20 +0000 (00:19 +0000)
lib/sqlalchemy/mapper.py
lib/sqlalchemy/objectstore.py

index 4d679beebdda24f9fdede4a34bf2c847d3de326d..e1ab2e47c1e404391818de12d0f4e11d50e34c2c 100644 (file)
@@ -387,6 +387,8 @@ class PropertyLoader(MapperProperty):
         self.key = key
         self.parent = parent
         
+        # TODO: if just a foreign key specified, figure out the proper "match_primaries" relationship
+        
         # if join conditions were not specified, figure them out based on primary keys
         if self.secondary is not None:
             if self.secondaryjoin is None:
@@ -437,8 +439,12 @@ class PropertyLoader(MapperProperty):
 
     def register_dependencies(self, objlist, uow):
         if self.secondaryjoin is not None:
-            uow.register_dependency(self.parent, self.mapper, None, None)
-            uow.register_dependency(self.mapper, None, self, objlist)
+            # with many-to-many, set the parent as dependent on us, then the 
+            # list of associations as dependent on the parent
+            # if only a list changes, the parent mapper is the only mapper that
+            # gets added to the "todo" list
+            uow.register_dependency(self.mapper, self.parent, None, None)
+            uow.register_dependency(self.parent, None, self, objlist)
         elif self.foreignkey.table == self.target:
             uow.register_dependency(self.parent, self.mapper, self, objlist)
         elif self.foreignkey.table == self.parent.table:
@@ -456,13 +462,11 @@ class PropertyLoader(MapperProperty):
 
         setter = ForeignKeySetter(self.parent, self.mapper, self.parent.table, self.target, self.secondary)
 
-        print "procdep " + repr(deplist)
         if self.secondaryjoin is not None:
             secondary_delete = []
             secondary_insert = []
             for obj in deplist:
                 childlist = getlist(obj)
-                print "added! " + repr(childlist.added_items())
                 for child in childlist.added_items():
                     setter.obj = obj
                     setter.child = child
index 334ee42e9fba47c61c9ad0630050115043de988e..a5b1dbb0719fc612043be2f7183cb7ab7ddf27a6 100644 (file)
@@ -108,6 +108,7 @@ def has_key(key):
         return False
 
 class UOWListElement(util.HistoryArraySet):
+    """overrides HistoryArraySet to mark the parent object as dirty when changes occur"""
     class listpointer(object): pass
         
     def __init__(self, obj, items = None):
@@ -122,11 +123,13 @@ class UOWListElement(util.HistoryArraySet):
         res = util.HistoryArraySet._setrecord(self, item)
         if res:
             uow().modified_lists.append(self.listpointer)
+            uow().register_dirty(self.obj())
         return res
     def _delrecord(self, item):
         res = util.HistoryArraySet._delrecord(self, item)
         if res:
             uow().modified_lists.append(self.listpointer)
+            uow().register_dirty(self.obj())
         return res
     
 class UnitOfWork(object):
@@ -227,14 +230,9 @@ class UnitOfWork(object):
             mapper = sqlalchemy.mapper.object_mapper(obj)
             mapperlist = mappers.setdefault(mapper, [])
             mapperlist.append(obj)
-        for array in self.modified_lists:
-            mapper = sqlalchemy.mapper.object_mapper(array.list.obj())
-            mapperlist = mappers.setdefault(mapper, [])
-            mapperlist.append(array.list.obj())
             
         for mapper in mappers.keys():
             mapperlist = mappers[mapper]
-            print repr(mapperlist)
             mapper.register_dependencies(mapperlist, self)
             
         mapperlist = mappers.keys()
@@ -247,11 +245,11 @@ class UnitOfWork(object):
                 return 0
         mapperlist.sort(compare)
         
+        # TODO: figure some way to process dependencies without saving a lead item,
+        # for the case when a list changes within a many-to-many
         for mapper in mapperlist:
             obj_list = mappers[mapper]
-            print "mapper " + mapper.table.name
             deplist = self.dependencies.get(mapper, [])
-            print "deps " + repr(deplist)
             for obj in obj_list:
                 mapper.save_obj(obj)
             for dep in deplist:
@@ -264,6 +262,8 @@ class UnitOfWork(object):
             item = item.list
             item.clear_history()
         self.modified_lists.clear()
+        
+        # TODO: deleted stuff
 
     def register_dependency(self, obj, dependency, processor, stuff_to_process):
         self.dependencies[(obj, dependency)] = True
@@ -272,4 +272,4 @@ class UnitOfWork(object):
             deplist.append((processor, stuff_to_process))
         
     
-uow = util.ScopedRegistry(lambda: UnitOfWork(), "thread")        
\ No newline at end of file
+uow = util.ScopedRegistry(lambda: UnitOfWork(), "thread")
\ No newline at end of file