Ahhh, thank you very much, the following seems to be working for me
now:
results = Session.query(Content, Column('distance', Float))\
.from_statement(text(stmt)).all()
contents = []
for content, distance in results:
content.distance = distance
contents.append(content)
return contents
For whatever reason it never occurred to me to try it that way.
Thanks again.
On Nov 8, 4:32 pm, Michael Bayer <[email protected]> wrote:
> 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 [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.