On Oct 7, 2013, at 6:06 AM, Julien Cigar <jci...@ulb.ac.be> 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) this is documented about midway through http://docs.sqlalchemy.org/en/rel_0_8/orm/inheritance.html#with-polymorphic , though maybe a little buried.
signature.asc
Description: Message signed with OpenPGP using GPGMail