Hello,

still working intensivly with joined table inheritance. I have troubles 
making a long join across many tables. I need to query players from 
"player_table" where on the other end, slots_hot.id == 'foo':

player_table = Table('players', meta,
     Column('id', Integer, primary_key=True),
     Column('description', Unicode(20)),
     Column('id_site', None, ForeignKey('sites.id'), nullable=False),
)

site_table = Table('sites', meta,
     Column('id', Integer, primary_key=True),
     Column('name', Unicode(40), nullable=False, unique=True),
     Column('type', Unicode(8)),
)

# inherits "site_table"
site_client_table = Table('site_clients', meta,
     Column('id', None, ForeignKey('sites.id'), primary_key=True),
     Column('id_client', None, ForeignKey('clients.id')),
)

playlist_table = Table('playlists', meta,
     Column('id', Integer, primary_key=True),
     Column('type', Unicode(8), nullable=False),
     Column('name', Unicode(30), nullable=False),
     Column('description', Unicode(40)),
)

# inherits "playlist_table"
playlist_site_table = Table('playlists_site', meta,
     Column('id', None, ForeignKey('playlists.id'), primary_key=True),
     Column('id_site', None, ForeignKey('site_clients.id')),
)

hotlink_table = Table('hotlinks', meta,
     Column('id', Integer, primary_key=True),
     Column('id_playlist', None, ForeignKey('playlists_site.id')),
     Column('id_hotslot', None, ForeignKey('slots_hot.id')),
)

slot_table = Table('slots', meta,
     Column('id', Integer, primary_key=True),
     Column('type', Unicode(8), nullable=False),
     Column('position', Integer, nullable=False),
     Column('match_all_options', Boolean, default=False, nullable=False),
     Column('id_slot', None, ForeignKey('slots.id')),
)

# inherits "slot_table"
hot_slot_table = Table('slots_hot', meta,
     Column('id', None, ForeignKey('slots.id'), primary_key=True),
     Column('name', Unicode(30)),
)

I'm trying to build the query using 
model.Player.query.select_from(player_table.join(site_table.join(site_client_table)))...
 
but then I'm getting this error when trying further 
.join(playlist_site_table):

Can't find any foreign key relationships between 'sites' and 
'_FromGrouping object'

Any idea how I could do this long join ?

Again, I tried using the clearer-to-read syntax:

model.Player.query.join(['site', 'playlists', 'hotlinks', 
'hotslot']).filter(model.SlotHot.c.id=='foo').all()

but of course, as soon as I hit inherited relations, it fails, so I have 
to build using either only filters:

.filter(Foo.c.id==Bar.c.id_foo).filter(Bar.c.id==Baz.c.id_baz).filter(...)

which makes it a 3 liner long query, or using tables directly with 
select_from(), which Im trying to do now, as show above.

Regards,
-- 
Alexandre CONRAD


--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to