Hi all,
I have some 'child' tables which inherit from the same 'master' table,
now I'd like to delete some entries from all tables. The 'where'-part
comes solely from the master table.
I have decided to use Concrete Table Inheritance since I don't need
the inheritance at points other than deleting, but I expect the tables
to have a lot of entries and at the moment I don't know how many child
tables I will have in the future. Also the delete process won't occur
often.

Each table has a compound primary key of user and room.
I use version 0.4.8 (and I can't change this)

I need a delete statement that deletes according to user_id and the
length of the room identifier.
Also master is only an abstract class, so I don't need to have a table
in my database (AFAIK).

master = Table('master', metadata,
    Column('user_id', Integer, ForeignKey('user.user_id',
ondelete='CASCADE'), primary_key=True),
    Column('room', Unicode(16), ForeignKey('room.id'),
primary_key=True)
)

child1 = Table('child1', metadata,
    Column('user_id', Integer, ForeignKey('user.user_id',
ondelete='CASCADE'), primary_key=True),
    Column('room', Unicode(16), ForeignKey('room.id'),
primary_key=True),
    Column('child1_data', Unicode(16))
)

child2 = Table('child2', metadata,
    Column('user_id', Integer, ForeignKey('user.user_id',
ondelete='CASCADE'), primary_key=True),
    Column('room', Unicode(16), ForeignKey('room.id'),
primary_key=True),
    Column('child2_data', Unicode(16))
)

join = polymorphic_union({
    'master': master,
    'child1': child1,
    'child2': child2
}, 'type', 'pjoin')

master_mapper = mapper(Master, master, with_polymorphic=('*',
vote_join), \
    polymorphic_on=vote_join.c.type, polymorphic_identity='vote_data')

child1_mapper = mapper(Child1, child1, inherits=master, \
    concrete=True, polymorphic_identity='child1')

child2_mapper = mapper(Child2, child2, inherits=master, \
    concrete=True, polymorphic_identity='child2')

Thanks for your time,
Mene

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to