I changed the object_mapper function from mapper.py to be this:
def object_mapper(object):
"""given an object, returns the primary Mapper associated with the object
or the object's class."""
if hasattr(object.__class__, '_base'):
return class_mapper(object.__class__._base)
return class_mapper(object.__class__)
Again, storing this info on the object in the _base variable and hacking the sqlalchemy code where necessary is probably not the best way to go about it. Let me know if you can think of a better way.
-Michael
On 3/26/06, Michael Carter <[EMAIL PROTECTED]> wrote:
It seems that this problem is giving me more trouble than I originally thought. If I create a many-to-many relation between the baseclass Test and some other class Foo to get the attribute foos, then it doesn't work with Test1 and Test2 instances. a = Test1(); a.foos.append(Foo()); objectstore.commit() => only adds the new Foo() but doesn't make an entry into the tests_foos table.
I think this is a related problem in that some of these properties are storing Test1 or Test2 as class_ when they need to be storing Test. Let me know what you think the problem is.
-Michael
On 3/26/06, Michael Carter <[EMAIL PROTECTED] > wrote:Great,
I'll check out the latest revision. There was another issue that I ran into a couple hours ago. That is, if you turn database echo on for the test2 example you can see that every time you make a call like Test.get(1) or Test.get(2) the object is reloaded from the database. I believe that this is because identity_key is called on the Test classes mapper so you get something like (<class 'Test'>, (2,)) as the identity_key, but then when a Test2 or Test1 does a lookup it uses a key like (<class 'Test2'>, (2,)). A very quick hack I did was to change mapper.py so the identity_key function looked like this:
if hasattr(self.class_, '_base'):
return objectstore.get_id_key(tuple(primary_key), self.class_._base)
return objectstore.get_id_key(tuple(primary_key), self.class_)
Then I added _base = Test to both the Test1 and Test2 class. I know this is a very fragile and far less than ideal fix -- I was just trying to isolate the problem. I'm not sure where that information could or should actually be stored.
Thanks again for extending the code to make these examples possible.
-Michael