Michael Bayer wrote:
>>>model.Player.query.join(['site', 'playlists', 'hotlinks',
>>>'hotslot']).filter(model.SlotHot.c.id=='foo').all()
>>>
>>
>>another thing im considering, along the lines of what I mentioned in
>>http://groups.google.com/group/sqlalchemy/browse_thread/thread/6b5b1cda1b657723#
>> , would look like this:
>>
>>query.join(['site', 'playlists', ('someprop', table.join(subtable)),
>>MySubclass.someprop])
>>
>>that is, "join to 'someprop' using this selectable as the target".
>>which is the same thing as if the mapper has "select_table" on it in
>>this case, but is a way to specify at the query level rather than the
>>mapper level.
>
>
> this feature is added in 4091 if youd like to try.
I'll test that tomorrow. I didn't have time for that today. I had a
quick look at it and the generated query doesn't look natural to me (at
least for what I'd do). Or maybe I don't understand how this works.
I'll try to make a simple test case of my joins.
Joining using strings is nice, it keeps the stamtment short. But these
strings reflect the the ORM relation. We should be able to join tables
as strings too.
Here's are my relations again:
'players' many-to-one 'site'
'site' inherited by 'site_client(site)'
'site_client(site)' one-to-many 'playlists'
As I said before, my problem here is to join from the player, via the
base 'site' to the inherited 'site_client' table.
I'd naturally want to do:
model.Player.join(['site', 'playlists']).filter(...)
But these strings seem to be the relation names. And of course, my Site
object doesn't have a 'site_client' as SiteClient uses "inherits=Site"
directly in the mapper(). So it's like "transparent" and there are no
way to get a grab of that relation. Site neither has a 'playlists'
relation, only SiteClient has.
So I've been playing with:
Player.query
.filter(Player.c.id_site==Site.c.id)
.filter(Site.c.id==SiteClient.c.id)
.filter(SiteClient.c.id==Playlist.c.id_site)
which doesn't work neither because .filter(Site.c.id==SiteClient.c.id)
generates "site.id = site.id" rather than the expected "site.id =
site_client.id". Which I understand, as I suppose it's part of the
inheritance process, that "transparency" I was talking about. So I
explicitly need to use my tables directly:
.filter(Site.c.id==site_client_table.c.id)
That join(['site', 'playlists', ('someprop', table.join(subtable)),
MySubclass.someprop]) you've proposed feels ugly.
It'd be great to be able to join using with strings and be able to grab
the relation in-between inherited tables, like:
Player.join(['site', 'site_client', 'playlists']).filter(...)
If 'site' doesn't have a 'site_client' relation(), check if we have a
'site_client' table as a fallback, and if we do, try to find the
relation with it. Then figure out that the 'site_client' table is mapped
to SiteClient, and keep on finding the next relation 'playlists' to join
it with.
Good night, and good luck. :)
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 [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
-~----------~----~----~----~------~----~------~--~---