Thursday, July 12, 2012

[Rails] Active Record - Record Count

I have been using ActiveRecord's find_by_sql to obtain the number of
records within a date range from a mysql database like this:

result = Xyz.find_by_sql("SELECT COUNT(*) as recordcount FROM xyz where
rdate > '#{start_date}' and rdate < '#{end_date}'")[0].recordcount

The problem with the above approach is that it is tied to mysql. Is
there a way that I can accomplish the above in a database independent
way?

Thanks for any input.

... doug

--
Posted via http://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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en-US.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate