Now that I've got the ActiveMapper code working to my satisfaction, I'm trying to add inheritance. This is proving to be no small task.

At the moment, I'm modelling things as follows:

class A(ActiveMapper):
        class mapping:
                a_id= column( Integer, primary_key=True )
                a_field= column( Unicode(40) )

class B(A):
        class mapping:
                b_id= column( Integer, foreign_key="a.a_id", primary_key=True )
                b_field= column( Unicode(40) )

(Note: these are totally fictitious classes. I'm actually working on an Identity provider for TurboGears.)

In the __init__ method for the ActiveMapperMeta class, I check to determine whether the class inherits from another class with a mapper and if so, the new mapper is created using the inherits keyword argument. This seems to work just fine when I'm creating new objects, however, retrieving those objects seems problematic.

Let's say I want to retrieve a B; I use the following code:

b= B.get(1)

Instead of my glorious B, I get:

Traceback (most recent call last):
  File "<console>", line 1, in ?
File "/Users/jeff/Projects/Web/sqlalchemy/lib/sqlalchemy/mapping/ mapper.py", line 272, in get
    return self._get(key, ident)
File "/Users/jeff/Projects/Web/sqlalchemy/lib/sqlalchemy/mapping/ mapper.py", line 286, in _get
    params["pk_"+primary_key.key] = ident[i]
IndexError: tuple index out of range


So I ask, "what gives?" Everything works fine if I execute:

b= B.select()[0]

But that's not very helpful.

--
Jeff Watkins
http://newburyportion.com/




-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to