Thanks for the quick reply!

I'm not interested in aliasing the result of the function, but rather 
aliasing the function itself. I have a number of expressions that would be 
nice to have as "attributes" of a model (for easy test / validation). Is it 
possible to bind an expression to a "virtual column" so that 
Person.select(:gender_title) and Person.select{gender_title} are equivalent 
to the above example of Person.select(Person.gender_title)?

Cheers!

On Thursday, December 4, 2014 1:16:58 PM UTC-8, Jeremy Evans wrote:
>
> On Thursday, December 4, 2014 12:42:39 PM UTC-8, Stefan Novak wrote:
>>
>> Hi!
>>
>> I'm trying to figure out a clean approach for referencing an expression 
>> within a Model. For example:
>>
>> class Person < Sequel::Model
>>   def self.gender_title
>>     Sequel.case({
>>     :M  => "Men's",
>>     :W  => "Women's"},
>>     "Not Applicable",
>>     :gender)
>>   end
>> end
>>
>>
>> I can run Person.select(Person.gender_title).sql and it generates the 
>> proper SQL. Is there a way to alias this expression to be 
>> Person.select(:gender_title)?
>>
>
> If you just want to alias the expression:
>  
> Person.select(Person.gender_title.as(:gender_title)).sql
>
> Thanks,
> Jeremy
>

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to