Find method use without sql in mind

I have a class Day with field date that represents a my sql date type,
YYYY-MM-DD. The Ruby type Date class has method, cweek, that returns
the calendar week that corresponds to a particular date. Ruby knows
cweek, but MySQL has no knowledge of this value. How do I run a find on
class Day, (Day.find :all … ) with condition ?
This is not a sql search but a Ruby search of all Day objects and their
corresponding date.cweek attribute.

How do I write this find method call?

Sam

I have a class Day with field date that represents a my sql date type,
YYYY-MM-DD. The Ruby type Date class has method, cweek, that returns
the calendar week that corresponds to a particular date. Ruby knows
cweek, but MySQL has no knowledge of this value. How do I run a find on
class Day, (Day.find :all … ) with condition ?
This is not a sql search but a Ruby search of all Day objects and their
corresponding date.cweek attribute.

How do I write this find method call?

MySQL has WEEK and WEEKOFYEAR functions, latter being equivalent to
WEEK(date,3)
so your condition might look like [WEEKOFYEAR(date) = ?,week].
Be sure to check if weekofyear is what you want, maybe you should use
week with different mode (second parameter).
And, of course, this is MySQL specific.

Regards,
Rimantas

http://rimantas.com/

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs