Thanks, Michael.

I've just tried your example with column_property, everything works
fine, except one thing:

Does column_property hides the properties it relies on?

So, once I added full_name, last_name and first_name disappeared, is
it possible to have them existing along with full_name?

Alex

On 26 сент, 20:19, Michael Bayer <[EMAIL PROTECTED]> wrote:
> Using comparable property as a selected element in SQL is a use case  
> which hasn't been addressed as of yet - the main usage was so far just  
> for producing WHERE/ORDER BY/etc. expressions.   In particular, the  
> comparable property doesn't have any query setup capabilities (i.e.  
> where it puts itself into a SQL expression as a column to be loaded)  
> nor any ability to receive result rows in an ORM entity loading  
> context.  This example though is just a column loading context.
>
> So for the exact thing you're trying to do, it would probably work if  
> you changed your __clause_element__ method to return a concatenation,  
> since column elements within sess.query(X) are expected to be scalar  
> ColumnElement objects:
>
> def __clause_element__(self):
>         r = None
>         for col in self.prop.descriptor.columns:
>                 if r is None:
>                         r = col
>                 else:
>                         r = r + text("' '") + col
>
> But really, if you're using comparable property as a loader, I  
> wouldn't use comparable property anyway.   It's much easier to achieve  
> as a regular column_property, which has full blown ORM capabilities,  
> meaning that it works as an entity attribute loader as well:
>
> mapper(MyClass, mytable, properties ={
>         'full_name':column_property(mytable.c.first_name + text("' '") +  
> mytable.c.last_name)
>
> })
>
> The comparison generated by the above property would look like:
>
>         WHERE table.firstname || ' ' || table.lastname = ?
>
> If you wanted to generate the criterion using AND the way your custom  
> prop comparator does, you can plug your comparator in using  
> comparator_factory - this option is available in rc1 but has not yet  
> been documented (its a TODO for the 0.5.0 milestone):
>
> mapper(MyClass, mytable, properties ={
>         'full_name':column_property(mytable.c.first_name + text("' '") +  
> mytable.c.last_name, comparator_factory =  
> JoinedValuesProperty.Comparator)
>
> })
>
> You still would want your __clause_element__ to return the SQL  
> concatenation expression.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to