【发布时间】:2017-01-03 16:55:59
【问题描述】:
我有以下两种型号:
class Appointment < ActiveRecord::Base
has_many :attendants, dependent: :destroy
belongs_to :user
end
class Attendant < ActiveRecord::Base
default_scope order('notification_time ASC')
belongs_to :appointment
end
下面的函数删除所有attendants,其中notification_time不在starts和ends之间:
def this_method_is_evil
starts = Time.parse(params[:start])
ends = Time.parse(params[:end])
@appointments_export = []
types = ['one', 'two', 'three']
user_appointments = current_user.appointments.where(type: types)
user_appointments.each do |i|
appointment = i
appointment.attendants = i.attendants.where('notification_time >= ? AND notification_time <= ?', starts, ends)
@appointments_export << appointment
end
end
所以基本上所有where('notification_time >= ? AND notification_time <= ?', starts, ends)没有返回的服务员都会从mysql数据库中删除。
这怎么可能?
【问题讨论】:
标签: mysql ruby-on-rails activerecord