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

index 30d9a296d6b3bc7dad92671099abb7dae7c5faa4..331e1dc285c5d2cd14133f31b3bb4e216a455613 100644 (file)
@@ -207,6 +207,7 @@ class AttributeManager(object):
         try:
             return self.attribute_history[obj][key]
         except KeyError, e:
+            # TODO: when an callable is re-set on an existing list element
             list_ = obj.__dict__.get(key, None)
             if callable(list_):
                 if passive:
index 27caa33a64027d148c4b311914775177fb551c96..173e35c37bb09813bb5afeb9807beae33d6d6b04 100644 (file)
@@ -594,7 +594,7 @@ class PropertyLoader(MapperProperty):
         if self.uselist is None:
             self.uselist = True
                     
-        (self.lazywhere, self.lazybinds) = create_lazy_clause(self.parent.table, self.primaryjoin, self.secondaryjoin)
+        (self.lazywhere, self.lazybinds) = create_lazy_clause(self.parent.table, self.primaryjoin, self.secondaryjoin, self.thiscol)
                 
         if not hasattr(parent.class_, key):
             #print "regiser list col on class %s key %s" % (parent.class_.__name__, key)
@@ -833,15 +833,15 @@ class LazyLoader(PropertyLoader):
             objectstore.uow().attribute_set_callable(instance, self.key, LazyLoadInstance(self, row))
 
 
-def create_lazy_clause(table, primaryjoin, secondaryjoin):
+def create_lazy_clause(table, primaryjoin, secondaryjoin, thiscol):
     binds = {}
     def visit_binary(binary):
-        if isinstance(binary.left, schema.Column) and binary.left.table == table:
+        if isinstance(binary.left, schema.Column) and (thiscol is binary.left or (thiscol is None and binary.left.table is table)):
             binary.left = binds.setdefault(table.name + "_" + binary.left.name,
                     sql.BindParamClause(table.name + "_" + binary.left.name, None, shortname = binary.left.name))
             binary.swap()
 
-        if isinstance(binary.right, schema.Column) and binary.right.table == table:
+        if isinstance(binary.right, schema.Column) and (thiscol is binary.right or (thiscol is None and binary.right.table is table)):
             binary.right = binds.setdefault(table.name + "_" + binary.right.name,
                     sql.BindParamClause(table.name + "_" + binary.right.name, None, shortname = binary.right.name))
                     
index 3095f1bff7b2448ee3bdc9149e75c5bf447d5fb1..997db3e6beb17859fc241247cdbd540860334f40 100644 (file)
@@ -138,7 +138,13 @@ class UnitOfWork(object):
         self.attributes.register_attribute(class_, key, uselist)
         
     def attribute_set_callable(self, obj, key, func):
+        # TODO: gotta work this out when a list element is already there,
+        # etc.
         obj.__dict__[key] = func
+        try:
+            del self.attributes.attribute_history[obj][key]
+        except KeyError:
+            pass
 
     
     def register_clean(self, obj):
@@ -302,7 +308,6 @@ class UOWTransaction(object):
             task.mapper.register_dependencies(self)
         
         for task in self._sort_dependencies():
-            print "exec task: " + str(task)
             task.execute(self)
             
     def post_exec(self):
@@ -357,8 +362,6 @@ class UOWTransaction(object):
         res.reverse()
         tasklist += res
 
-        print repr(self.tasks.values())
-        print repr(tasklist)
         assert(len(self.tasks.values()) == len(tasklist)) # "sorted task list not the same size as original task list"
 
         import string,sys
@@ -435,60 +438,6 @@ class UOWTask(object):
         make_task_tree(head, t)
         return t
         
-    def old_sort_circular_dependencies(self, trans):
-        dependents = {}
-        d = {}
-
-        def make_task():
-            t = UOWTask(self.mapper, self.isdelete, self.listonly)
-            t.dependencies = self.dependencies
-            t.taskhash = d
-            return t
-
-        head = make_task()
-        for obj in self.objects:
-            print "obj: " + str(obj)
-            task  = make_task()
-            d[obj] = task
-            if not dependents.has_key(obj):
-                head.objects.append(obj)
-            for dep in self.dependencies:
-                (processor, targettask) = dep
-                if targettask is self:
-                    childlist = processor.get_object_dependencies(obj, trans, passive = True)
-                    for o in childlist.added_items() + childlist.deleted_items():
-                        whosdep = processor.whose_dependent_on_who(obj, o, trans)
-                        if whosdep is not None:
-                            (child, parent) = whosdep
-                            if not d.has_key(parent):
-                                d[parent] = make_task()
-                            if dependents.has_key(child):
-                                p2 = dependents[child]
-                                wd2 = processor.whose_dependent_on_who(parent, p2, trans)
-                                
-                            d[parent].objects.append(child)
-                            dependents[child] = parent
-                            print "dependent obj: " + str(child) + " is dependent in relation " + str(obj) + " " + str(o)
-                            if head.objects.contains(child):
-                                del head.objects[child]
-
-        def printtask(t):
-            print "l1"
-            print repr([str(v) for v in t.objects])
-            for v in t.objects:
-                t2 = t.taskhash[v]
-                print "l2"
-                print repr([str(v2) for v2 in t2.objects])
-                for v3 in t2.objects:
-                    t3 = t.taskhash[v3]
-                    print "l3"
-                    print repr([str(v4) for v4 in t3.objects])
-#                printtask(t2)
-        print "sorted hierarchical tasks: "
-        printtask(head)
-        raise "hi"
-        return head
-        
     def __str__(self):
         if self.isdelete:
             return self.mapper.primarytable.name + " deletes " + repr(self.listonly)