On Tuesday 07 October 2008 00:01:58 Michael Bayer wrote:
> On Oct 6, 4:22 pm, [EMAIL PROTECTED] wrote:
> > hi
> > i have a query where
> > q = ...q.initial
> > q = q.join( some_link_name )
> > ...q.otherstuff
> > q = q.add_entity( target_klas_of_the_above_link)
> > ...
> > this used to work ok, but recently it went doing cartesian
> > products because the join made itself an alias.
>
> recently as of when ?   q.join() will make a subquery of an alias
> if you're joining to a joined-table class.  This because the syntax
> A join (X join Y) works very poorly, so it detects that and instead
> says A join (SELECT * from X join Y).  I.e. treating the
> "selectable" of X join Y like the single unit it is.   But 0.5 has
> been doing that since day one and 0.4 does it too, though 0.4 might
> not do it in the same set of cases.
>
> > i made it into:
> > q = ...q.initial
> > q = q.add_entity( target_klas_of_the_above_link)
> > q = q.join( some_link_name )
> > ...q.otherstuff
>
> that works ?   does the join no longer create the subquery ?

neither makes a subquery. The child is declared as polymorphic  
although it has no inheritants (with_polymorphic= ('*', None) ), 
probably that triggers the aliasing... ahha i recently changed the 
dbcook's select_table=... into with_polymorphic=... and that might be 
the "when".

but anyway, it may break on another scenario where the child _is_ 
polymorphic.

here the situation:

q.join(child) then q.add-entity(child) does:
select child.whatever, parent.whatever
FROM child, X, parent join child as child_1 
 on parent.child_id == child_1.id  LEFT OUTER JOIN 
whatever-eagerloading
-> decartX

q.add-entity(child) then q.join(child) does:
select child_1.whatever, parent.whatever
FROM X, parent join child as child_1 
 on parent.child_id == child_1.id  LEFT OUTER JOIN 
whatever-eagerloading
-> no decartX, ok

so in either case the joined child is aliased, but in the working case 
there is no another non-aliased in the FROM.

i tried the other way, query(child).join(parent-backref),
and this does not work either way:

q.add-entity(parent) then q.join(parent) 
does add parent in the FROM, so decartX

q.join(parent) then q.add-entity(parent) 
does not add parent in the FROM, but dies with:
  no such column: parent.somecolumn
there is only parent_1 in the FROM, while the select wants 
parent.all-the-columns.

to me there's something fishy about all this, it does not work (or 
break) in the same way.
do u want it as ticket? not sure how to formulate it.

fixing dbcook to not give false with_polymorphics makes all cases work 
as there no aliasing, but this is a workaround - IMO false 
polymorphics should be ignored - or errored and this add_entity/join 
business has to be fixed too.

ciao
svilen

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