Thanks Jarin for the idea!

I used named scopes in my user model like this:

named_scope :age_gt, lambda { |age| { :conditions => ['birthdate < ?',
age.to_i.years.ago] }}
named_scope :age_lt, lambda { |age| { :conditions => ['birthdate > ?',
age.to_i.years.ago] }}

now I don't need to use a special query to achieve this.



On 21 helmi, 01:06, Vincent P <ease...@gmail.com> wrote:
> Converting to datetime object is an excellent idea.  Thanks Jarin!
>
> On Feb 20, 12:02 am, Jarin Udom <ja...@robotmo.de> wrote:
>
> > For that particular search, you'll have to build your own search
> > queries. The only other option is to load all records into memory and
> > filter by the age instance method, but of course you don't want to do
> > that.
>
> > Searchlogic will still make the search easier though. You can convert
> > the age from an integer into a datetime object and use it in a
> > Searchlogic search like so:
>
> > age = 29
>
> > User.birthdate_greater_than(age.years.ago).birthdate_less_than((age -
> > 1).years.ago).all
>
> > Hope this helps!
>
> > Jarin Udom
> > Robot Mode LLC
>
> > On Feb 19, 10:30 pm, Ease Bus <ease...@gmail.com> wrote:
>
> > > Can I use something like searchlogic to search for objects based on
> > > the return values of instance methods?  E.g., I'd like to search for
> > > users of a certain "age" but age is not a column, it's an instance
> > > method, returning the age value calculated from the birthdate, which
> > > is a column.
>
> > > Is there a quick way like searchlogic to do this or do I have to build
> > > my own search queries?   Thanks.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to