I want to get recipes which belongs to a particular category and having
a particular flag. So I need both joins recipe-category and recipe-flag.
Michael Bayer napsal(a):
>
> On Apr 30, 2007, at 8:40 AM, ml wrote:
>
>> Hi!
>>
>> I have 2 relations:
>> - recipes-categories (M:N)
>> - recipes-flags (M:N)
>>
>> I'd like to get something like:
>> SELECT recipes.title FROM recipes
>> JOIN _recipes_ctgs_recipes
>> ON _recipes_ctgs_recipes.id_recipe = recipes.id
>> JOIN recipes_ctgs
>> ON _recipes_ctgs_recipes.id_recipes_ctg=recipes_ctgs.id
>> JOIN _recipes_flgs_recipes
>> ON _recipes_flgs_recipes.id_recipe = recipes.id
>> JOIN recipes_flgs
>> ON _recipes_flgs_recipes.id_recipes_flg=recipes_flgs.id
>> WHERE recipes_ctgs.title='cat1' AND recipes_flgs.title='flag1'
>>
>> when I run
>> sess.query(Recipe).join("ctgs").join("flgs").select(...)
>> it fails with
>>
>> sqlalchemy.exceptions.SQLError: (ProgrammingError) table name
>> "_recipes_ctgs_recipes" specified more than once
>>
>> where "_recipes_ctgs_recipes" is a secondary table. Full example
>> attached.
>
> well, yeah, youre joining against the same relationship twice.
> going from "ctgs" to "flgs" makes it essentially a self referential
> join on "recipes". i dont understand what youre trying to query for
> there but my intuition tells me theres probably some better way to
> lay out that query without 5 joins in between. if not, youll have to
> lay out the self referential part manually using table aliases.
>
> (note to SA old schoolers - see why i hesitated so much to add auto-
> joins across relationships ? every new feature spawns a whole new
> class of user issues)
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---