svilen wrote: > On Friday 11 January 2008 16:12:08 Alexandre Conrad wrote: > >>Channel -> Playlist -> Media >>Channel -> CatalogChannel(Catalog) -> Media >> >>(Media has a fk to Catalog, not CatalogChannel) >>The only element I have, is "playlist" (instance of Playlist). At >>this point, I need to find out the available Media of the >>Playlist's Channel's catalog so I can attach them to the Playlist. >> >>At first, I tryied out: >> >>Media.query.join(["catalog", >>"channel"]).filter(Channel.c.id==playlist.id_channel).all() >> >>But then it complains that "channel" is not part of the Catalog >>mapper. Catalog ? I want it to be looking at CatalogChannel, this >>is the one having the "channel" relation, not Catalog. > > i see what u want, but formally (computer languages are formal, SA is > a language) u are contradicting yourself. u said above that > media points to catalog and not to catalogchannel. How u expect it to > find a .channel there?
I was expecting that SA would know that from the polymorphic "type" flag. I have a "catalog" relation on media. When I do media.catalog, it doesn't just return a Catalog object, but really a CatalogChannel object (which is the whole point of polymorphic inheritance). And I thought it could figure out channel from that. But Mike said no. :) That's why he talked about having some extra API query methods: Media.query.join_to_subclass(CatalogChannel).join("channel").filter(Channel.c.id==playlist.id_channel).all() We could even join classes only directly (isn't this ORM after all?): Media.query.join([CatalogChannel, Channel]) > your query above is missing the isinstance-filter specifying that u > need catalogchannels and not just any catalogs. i'm not sure how this > would be expressed in SA but it has to be explicit - and probably > somewhere on level of tables. > have u tried > Media.query.join( ["catalog", "id", "channel"])... ??? Nope, that doesn't work, it's like doing (["catalog", "catalog", "channel"]) 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 -~----------~----~----~----~------~----~------~--~---