On Nov 4, 2008, at 12:24 PM, john.goodleaf wrote:
> I must be doing something wrong here. I've put a function call into > the mapper like so: > > mapper(Instance, instances, > properties={'LocalInstanceName': > column_property(select( > [func.fnLocalizedInstanceName(bindparam('eng'), > > bindparam(instances.c.InstanceID)) ]))} ) > InstanceID is a column so you wouldn't put that inside of a bind parameter. Also the "eng" bind parameter is probably not appropriate inside of column_property() for general query usage, since it requires a value at query execution time which is probably not available. While you can specify bind parameter values with Query using the params() method, the Query object is executed against the Instance object in other scenarios, such as when attributes are refreshed, and the "eng" value will not be available in that case. As an example, what would the value of "eng" be if I were to say "session.query(Instance).get(5)" ? A solution which might be more what you're looking for is this: class Instance(object): ... def get_localized_instance_name(self, eng): return object_session(self).execute(select([func.fnLocalizedInstanceName(eng, self.InstanceID)]).scalar() that way when you have an Instance, you can call myinstance.get_localized_instance_name(<value of eng>) to get the desired result. If OTOH the "eng" value can be derived from the Instance row, we can revisit the column_property() approach, which in reality only grants a small performance advantage in that the function can be executed at the same time the Instance object itself is selected, as opposed to a second SELECT when an accessor is called. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---