这是我的SQL查询:
从answer_histories INNER JOIN中选择answer_histories。* material_progresses ON material_progresses.id = answer_histories.material_progress_id INNER JOIN learning_histories 在learning_histories.id = answer_histories.learning_history_id和 learning_histories.deleted_at是NULL和 learning_histories.completed_at IS NOT NULL where answer_histories.deleted_at IS为NULL,answer_histories.slide_id = 3 和material_progresses.site_id = 1和learning_histories.id IN (SELECT MAX(learning_histories.id)FROM learning_histories WHERE learning_histories.completed_at IS NOT NULL GROUP BY learning_histories.material_progress_id);
我已经做了一些事情。但是失败了
我的learning_history.rb
> class LearningHistory < ActiveRecord::Base extend Enumerize
> acts_as_paranoid records_with_operator_on :create, :update, :destroy
> belongs_to :material_progress has_many :answer_histories scope
> :completed, ->{ where.not(completed_at: nil) } enumerize :status,
> :in => [:not_attempted, :incomplete, :completed, :failed, :passed, :browsed],
> :default => :not_attempted after_create :update_material_progress after_save :reset_material_progress, :if
> => :reset? def completed?
> [:completed, :failed, :passed].include?(status.try(:to_sym)) end end end