Yes. I just read in the TG 1.0.x changelog that it should even work
fine with SA 0.6. I was convinced it only supported SA 0.4. I'm glad I
was wrong about that.
Apart from that, I did indeed forget to add the PK constraint. Now the
inheritance tree is working just fine.

Thanks again.


On Nov 5, 7:22 pm, David Gardner <dgard...@creatureshop.com> wrote:
> I'm currently supporting a TG 1.x app, it works just fine with 0.5.6.
> If you use TG 1.0 you will get a deprecation warning about the
> Session.mapper.
> However I believe TG 1.1 uses 
> thehttp://www.sqlalchemy.org/trac/wiki/UsageRecipes/SessionAwareMapper
> which won't give you a deprecation warning.
>
> With that said you would need to check your code for the usual 0.4->0.5
> issues.
>
>
>
>
>
> exhuma.twn wrote:
> > Unfortunately I am running an TurboGears 1.0 app. which currently only
> > supports SA0.4
> > Porting it to TurboGears 2.0 would be... a lot of work... :)
>
> > I'll try your solution this evening. Actually the table has a pkey in
> > the DB. I must have forgotten to add it in the SA model.
>
> > On 5 nov, 02:43, Michael Bayer <mike...@zzzcomputing.com> wrote:
>
> >> On Nov 4, 2009, at 7:33 PM, exhuma.twn wrote:
>
> >>> Hi,
>
> >>> All the docs only explain how to do inheritance using a simple "parent
>
> >>>> child" model. But what about "parent > child > grandchild"? I tried
>
> >>> the following but I get an error:
>
> >>> <code>
>
> >>> thing_table = Table( 'thing', metadata,
> >>>      Column( 'uuid', String(36), primary_key=True,
> >>> default=func.uuid_generate_v1() ),
> >>>      Column( 'reporter', String(30), nullable=False )
> >>>      Column( 'type', String(30), nullable=False )
> >>>      )
>
> >>> mineral_table = Table('mineral', metadata,
> >>>    Column('uuid', String(36), primary_key=True, ForeignKey
> >>> ('thing.uuid')),
> >>>    Column( 'family', String(30), nullable=False )
> >>> );
>
> >>> crystal_table = Table( 'crystal', metadata,
> >>>        Column('uuid', String(36), ForeignKey('mineral.uuid')),
> >>>        Column('label', String(30)))
>
> >>> class Thing(object): pass
> >>> class Mineral(Thing): pass
> >>> class Crystal(Mineral): pass
>
> >>> mapper( Thing, thing_table, polymorphic_on=thing_table.c.type,
> >>> polymorphic_identity='thing' )
> >>> mapper(Mineral, mineral_table, inherits=Thing,
> >>> polymorphic_identity='mineral')
> >>> mapper(Crystal, crystal_table, inherits=Mineral,
> >>> polymorphic_identity='crystal')
>
> >>> </code>
>
> >>> When I create the mappings like this, the model loads correctly, but I
> >>> cannot create "Crystal" instances:
>
> >> I think you need a primary key on crystal_table for it to be an  
> >> official member of the joined table inheritance club.  Also 0.4.6 is a  
> >> very old SQLA version and you'd have a lot more query fluency if you  
> >> were on 0.5 at least.
>
> >>>>>> x = Crystal()
> >>>>>> x.family='kjdfh'
> >>>>>> session.save(x)
> >>>>>> session.flush()
>
> >>> 2009-11-05 01:21:32,795 sqlalchemy.engine.base.Engine.0x..2c INFO
> >>> BEGIN
> >>> 2009-11-05 01:21:32,801 sqlalchemy.engine.base.Engine.0x..2c INFO
> >>> SELECT uuid_generate_v1() AS uuid_generate_v1_1
> >>> 2009-11-05 01:21:32,801 sqlalchemy.engine.base.Engine.0x..2c INFO {}
> >>> 2009-11-05 01:21:32,805 sqlalchemy.engine.base.Engine.0x..2c INFO
> >>> INSERT INTO thing (uuid, type) VALUES (%(uuid)s, %(type)s)
> >>> 2009-11-05 01:21:32,806 sqlalchemy.engine.base.Engine.0x..2c INFO
> >>> {'type': 'rock', 'uuid': '2bb7593c-c9a1-11de-8367-001d720c19db'}
> >>> 2009-11-05 01:21:32,814 sqlalchemy.engine.base.Engine.0x..2c INFO
> >>> INSERT INTO mineral (uuid, family) VALUES (%(uuid)s, %(family)s)
> >>> 2009-11-05 01:21:32,815 sqlalchemy.engine.base.Engine.0x..2c INFO
> >>> {'uuid': '2bb7593c-c9a1-11de-8367-001d720c19db', 'family': 'kjdfh'}
> >>> 2009-11-05 01:21:32,896 sqlalchemy.engine.base.Engine.0x..2c INFO
> >>> COMMIT
>
> >>> Oddly, the "Crystal" instance is never saved. Any ideas? I am running
> >>> this using SQLAlchemy 0.4.6.
>
> --
> David Gardner
> Pipeline Tools Programmer
> Jim Henson Creature Shop
> dgard...@creatureshop.com
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to