one hunch is that the B.get() method wants to receive a_id and b_id as the arguments, i.e. B.get(1,1). the primary key of an inherited mapper, across 'tablea' and 'tableb', is determined by:

x = join(tablea, tableb)

(x.onclause is now tablea.a_id==tableb.b_id)

the mappers primary_key cols, which are used in a get() == x.primary_key

the join will determine the primary key via: left.primary_key + right.primary_key

which is:  [a.a_id, b.b_id]

yup, i bet thats just it then.

So.  what kind of rule to make this more intuitive?  how about this:

[c for c in left.primary_key if not c.foreign_key.references(right)] + [c for c in right.primary_key if not c.foreign_key.references(left)]

?

On Mar 3, 2006, at 3:55 PM, Jeff Watkins wrote:

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



-------------------------------------------------------
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