forget it, I missed this in the docs :"Note that when using joined eager loaders with relationships, the tables used by the eager load’s join are anonymously aliased. You can only order by these columns if you specify it at the relationship() level. To control ordering at the query level based on a related table, you join() to that relationship, then order by it"
On 06/23/2010 11:16, Julien Cigar wrote:
Hello all,
always with the following:
orm.mapper(Human, table.human)
orm.mapper(Content, table.content,
polymorphic_on = table.content.c.content_type_id,
properties = {
'owner' : orm.relationship(
Human,
lazy = 'joined',
innerjoin = True,
)
}
)
Is there a way to order_by on the 'owner' property of the Content mapper
directly without having to join the related class (Human in this case)
again ?
I thought something like :
Content.query.filter(Content.container_id==789).\
order_by(Content.owner.login)
but it doesn't work : AttributeError: Neither 'InstrumentedAttribute'
object nor 'Comparator' object has an attribute 'login'
It works with
Content.query.join(Human).\
filter(Content.container_id==789).\
order_by(Human.login)
but then Human is joined two times, one for the explicit .join() and one
for the 'owner' relationship (... JOIN human ON human.id =
content.owner_id JOIN human AS human_1 ON human_1.id = content.owner_id
...)
Also, if I put lazy = 'select' in place of lazy = 'joined' for the above
relationship() and that I do :
Content.query.join(Human).\
filter(Content.container_id==789).\
order_by(Human.login)
and then if I access the 'owner' property of one of those selected
objects SQLAlchemy issues a SELECT again, .. why ? Is there a way to
tell SQLAlchemy that the .join(Human) of the above query is in fact the
'owner' property of Content .. ?
Thanks,
Julien
-- No trees were killed in the creation of this message. However, many electrons were terribly inconvenienced. -- 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.
<<attachment: jcigar.vcf>>
