things = Thing.find_all_by_field('start_at'..'end_at')

On Feb 9, 7:29 am, Gabi Ge <[email protected]> wrote:
> I'd like to search for invoices in the database, having the date range
> set (from, to). The problem is that invoices whose issue dates match the
> 'from' or 'to' dates will not show up in results.
>
> For example:
> Created an invoice today ("2009-02-09"), and I'm searching by issue_date
> between from and to, these are the params:
>
>  "filter"=>{"from"=>"2009-02-09", "to"=>"2009-02-09"}
>
> In the model I have the sql conditions, as well as a scope, looks like
> this:
>
>  self.cond = Array.new
>  self.cond << ["invoices.issue_date >= ?", from] unless from.blank?
>  self.cond << ["invoices.issue_date <= ?", to] unless to.blank?
>  result = join_conditions
> ---
>  named_scope :filter, lambda { |invoice_filter|
>     { :conditions => invoice_filter.sql_conditions }}
>
> The scope gets a filter object that has both 'from' and 'to' fields set.
> If I set the 'to' field to tomorrow's date, then the invoice will
> appear, but I don't understand why it wouldn't work as is since there
> are '<=' & '>=' comparisons in conditions.
>
> Any help or suggestion would be appreciated!
> --
> Posted viahttp://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to