On Jan 23, 2008, at 10:25 AM, Alexandre Conrad wrote:

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

join() takes a second argument which is the ON clause of the join,  
just specify that.

>
> 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(...)

are you using select_table with your mappers now ?  If so, you can  
specify criterion in terms of the subclass mappers, just like I  
illustrated in the previous thread.


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