Hello again.

I have replaced joinedload_all option with subqueryload_all and the query works
as expected: order of the results is correct.


Ladislav Lenart


On 17.9.2012 13:19, Ladislav Lenart wrote:
> Hello.
> 
> Imagine the following ORM definition in PostgreSQL:
> 
>     class Node(Base):
>         __tablename__ = 'node'
>         id = Column(Integer(), primary_key=True)
>         parent_id = Column(Integer(), ForeignKey('node.id'))
>         # more data...
> 
> with the following query method:
> 
>     def path_to_root(self, root_id=None, load_all=True):
>         cls = self.__class__
>         q_base = session.query(cls).filter(cls.id == self.id)
>         q_cte = q_base.cte(name='q_cte', recursive=True)
>         q_cte_alias = aliased(q_cte, name='q_cte_alias')
>         cls_alias = aliased(cls, name='cls_alias')
>         q_rec = session.query(cls_alias)
>         q_rec = q_rec.filter(cls_alias.id == q_cte_alias.c.parent_id)
>         q_rec = q_rec.filter(cls_alias.id != root_id)
>         q_cte_union = q_cte.union_all(q_rec)
>         q = session.query(cls).select_from(q_cte_union)
>         q = q.options(joinedload_all(cls.foo, Foo.bar)) # <-- marked line
>         return q
> 
> It should return path from the receiver node upwards to the root.
> 
> The query works as expected without the marked line. However the order of 
> result
> items is reversed when the marked line is present. I was under the impression
> that joinedload option should not have observable side-effects.
> 
> Was I wrong?
> 
> Can I preload dependent data by some other means without semantic change in 
> the
> query?
> 
> 
> Thank you in advance,
> 
> Ladislav Lenart

-- 
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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to