On Nov 8, 2010, at 6:17 PM, William wrote: > When I create a non-primary mapper for my class to add an additional > computed value in certain contexts when the query runs I get the > error: > > AssertionError: No such polymorphic_identity 'M' is defined > > This works fine with the primary mapper as several classes are defined > as having polymorphic identities. Is there a reason why this wouldn't > work?
its not something I've ever tried, I believe a non_primary mapper replacing the "base" for a set of inherited mappers might not be very straightforward since the NP doesn't have the polymorphic_map set up. You might need to copy that attribute over from the primary. But NP mappers are almost a non-use case at this point. > > It's entirely possible that I'm approaching this in the wrong way. One > of the primary queries used in our application does a distance search > and requires that several distances be calculated in order to perform > the query in a reasonable timeframe. This query is currently being > executed as a text statement. I'd like to end up with the normal > behaviour of orm but have the distance value attached to the object > when all is said and done. Usually you'd define additional computed values on the primary mapper (i.e. column_property(), or deferred(), which lets you enable their inline-loading via options()). In my own practice I use so called "hybrid" properties for things like this, so that I can add them to a query independently, i.e. query(MyClass.id, MyClass.some_computed_value), or I can get at them on existing instances using Python expressions, myobject.some_computed_value. hybrid properties will be featured prominently in 0.7, and you can use them now based on the derived_attributes/attributes.py example. Or use a plain descriptor that uses object_session(self).query() to invoke a supplemental query lazily. -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@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.