On Thursday, December 4, 2014 1:32:43 PM UTC-8, Stefan Novak wrote:
>
> 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)?
>

There are a couple ways to do that, though nothing built in.

If you only care about select, you could override the select method for the 
Person dataset, scan for gender_title, and replace it with the appropriate 
expression before calling super

If you care about something more, you pretty much need to override the 
literal method for the Person, look for :gender_title or 
Sequel.expr(:gender_title), and return literal(Person.gender_title) instead 
of calling super.

But either way is going to be confusing and non-idiomatic for Sequel users. 
If I had to have something similar to the API you are proposing, I'd add a 
dataset method to Person with a unique name that did the appropriate 
replacement of :gender_title with Person.gender_title.

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