UserがScheduleに対して日課を記録します。
各モデルは以下の通りです。
# == Schema Information # # Table name: users # # id :integer not null, primary key # name :string(255) # created_at :datetime not null # updated_at :datetime not null # class User < ActiveRecord::Base has_many :schedules end
# == Schema Information # # Table name: schedules # # id :integer not null, primary key # do_date :date # user_id :integer # created_at :datetime not null # updated_at :datetime not null # class Schedule < ActiveRecord::Base belongs_to :user end
↓で先月に1日でも日課を行ったUserを取得できます。
start_day = Date.today.prev_month.beginning_of_month end_day = Date.today.prev_month.end_of_month User.includes(:schedules).where(schedules: { do_date: [start_day..end_day] })
これを、where.not
にして、先月に日課を全く行っていないUserを取得できると思いましたが、
何も出てきません。
start_day = Date.today.prev_month.beginning_of_month end_day = Date.today.prev_month.end_of_month User.includes(:schedules).where.not(schedules: { do_date: [start_day..end_day] })
先月に日課を全く行っていないUserを取得するには、どうすればよいでしょうか?
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/06/02 08:11