On Jul 6, 2011, at 5:47 AM, Arturo Sevilla wrote:

> Hi,
> 
> I have a mapping between a table row and a python field, for which I have a 
> synonym. I've read the documentation and it says: "Each of column_property(), 
> composite(), relationship(), and comparable_property() accept an argument 
> called comparator_factory." For which I assume that synonym() doesn't have a 
> comparator_factory, however when I peeked into the library's code I saw this 
> definition:
> 
> def synonym(name, map_column=False, descriptor=None, 
>                         comparator_factory=None, doc=None):
> 
> Does this means that you can actually customize a comparator_factory for 
> synonym? I ask because in my "proxied" mapped column I have a custom 
> comparator_factory which defines a "method" for that property so I can do 
> something like filter(my_prop.my_method()). However, this method doesn't get 
> proxied by orm.synonym, with or without defining the same comparator_factory 
> in orm.synonym(). Part of my mapper is:
> 
>         '_geolocation': orm.composite(GeoPoint, event.c.GeoLatitude, 
>                                       event.c.GeoLongitude,
>                                       comparator_factory=GeoPointComparator),
>         'geolocation': orm.synonym('_geolocation',
>                                    comparator_factory=GeoPointComparator)
> 
> I really don't have a problem using filter(Klass._geolocation.near(param1, 
> param2)) for my code (near being defined in GeoPointComparator). I made this 
> post to see if someone with more insight can help to clarify this, so that I 
> don't have to peek very deeply into the code in order to look for the answer 
> of this behavior.

If you pass a PropComparator class to the comparator_factory argument of 
"synonym()", an instance of that class will be used when Python comparison 
operations are invoked upon the mapped attribute at the class level.   Whatever 
behavior it defines from there is what takes place, which should include the 
__getattr__() proxying that would locate your "near()" method.

If things don't work, provide a short, succinct,  working (meaning, shows the 
problem) test case and we can see what might be the issue.


-- 
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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to