On Mon, Oct 07, 2013 at 11:28:21AM -0400, Michael Bayer wrote:
>
> On Oct 7, 2013, at 6:06 AM, Julien Cigar <[email protected]> wrote:
>
> > Hello,
> >
> > I have the following query:
> >
> > entity = orm.with_polymorphic(
> > Content, [Event, News]
> > )
> >
> > q = db.Session.query(entity)
> >
> > The "Event" class has a "country" property:
> >
> > orm.mapper(Event, table['event'], inherits = Content,
> > polymorphic_identity = _get_type_id('event'),
> > properties = {
> > 'country' : orm.relationship(
> > Country, lazy = 'joined'
> > )
> > })
> >
> > I would like to order my query above with .order_by(Country.name)
> >
> > So I tried:
> >
> > q = q.outerjoin(Event.country).options(
> > orm.contains_eager(Event.country)
> > ).order_by(
> > Country.name
> > )
> >
> > but SQLAlchemy complains with:
> >
> > ArgumentError: Can't find property 'country' on any entity
> > specified in this Query. Note the full path from root
> > (Mapper|Content|content) to target entity must be specified.
>
> you need to state all work with Event in terms of the with_polymorphic
> construct you've created:
>
> outerjoin(entity.Event.country)
Thank you, it works as expected with:
q = q.outerjoin(entity.Event.country).options(
orm.contains_eager(entity.Event.country)
).order_by(
Country.name
)
>
> this is documented about midway through
> http://docs.sqlalchemy.org/en/rel_0_8/orm/inheritance.html#with-polymorphic ,
> though maybe a little buried.
>
--
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 unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/groups/opt_out.