我有三个模型,每个模型都是这样连接的:Groups
which has many Students
which has many Absences
.
Absences
有一个名为created_on
.
我只有一个组 id,想获取今天缺席的所有学生。
我在我的Student
模型中创建了这个方法:
# Inside student.rb
def self.absent_today_in_group (group)
#SQLITE
find(:all, :joins => :absences, :conditions => ["STRFTIME('%d', created_on) = ? AND STRFTIME('%m', created_on) = ?", Date.today.day, Date.today.month])
#POSTGRES
#find(:all, :joins => :absences, :conditions => ["EXTRACT(DAY FROM created_on) = ? AND EXTRACT(MONTH FROM created_on) = ?", Date.today.day, Date.today.month])
end
为什么该查询不返回任何内容?然后我怎么能检查group_id?