On Friday 11 January 2008 16:12:08 Alexandre Conrad wrote: > svilen wrote: > >>Here is the syntax followed by the generated query: > >> > >> query.filter(Catalog.c.id==CatalogChannel.c.id) > >> WHERE catalogs.id = catalogs.id > > > > why u need such a query? > > that's exactly what (inheritance) join does, and automaticaly - > > just query( CatalogChannel).all() would give u the above query. > > I have hidden the full concept I'm working on and only focused my > problem. Here's my full setup the query is involved with: > > 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? Forget DB; think plain objects. u point to a base class but expect it always to have an attribute that belongs to one of children classes... which is implicitly saying that while pointing to base-class AND u need only those pointing to the child-class AND the attribute is whatever. (i.e. isinstance(x,CatChanel) and x.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"])... ??? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---