On Tuesday 20 November 2007 11:37:29 Gaetan de Menten wrote: > Hi people, > > I have some classes with "standard python" properties which target > another python object and also uses several columns in the > database. I also got a global factory function to create an > instance of that target object out of the value of the columns (the > class of that target object can vary). > > Now, I'd like to use those properties in filter criteria, as so: > > session.query(MyClass).filter(MyClass.my_prop == value)... > session.query(MyClass).filter_by(my_prop_name=value)... > > I've tried using composite properties for that (passing the factory > function instead of a composite class), and it actually works, but > I'm a little nervous about it: can I have some bad side effect > provided that in *some* cases (but not always) the target object is > loaded from the database. > > I also dislike the fact I have to provide a __composite_values__ on > all the possible target classes, while in my case, I would prefer > to put that logic on the property side. I'd prefer if I could > provide a callable which'd take an instance and output the tuple of > values, instead of the method. Would that be considered a valid use > case for composite properties or am I abusing the system? > > I've also tried to simply change those properties to descriptors so > that I can override __eq__ on the object returned by accessing the > property on the class. This worked fine for "filter". But I also > want to be able to use filter_by. So, I'd wish that > query(Class).filter_by(name=value) would be somehow equal to > query(Class).filter(Class.name == value), but it's not. filter_by > only accepts MapperProperties and not my custom property. what would query(Class).filter(Class.name == value) mean in the case of plain property? the Class.name == value would selfconvert to SA.expression?
then what if the filter_by(**kargs) is simply doing _and( getattr( Class, k) == v for k,v in kargs,items() ) i dont understand the _composite bit, why u have to bother with that? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---