我想为仅托管标记为完成的约会的用户创建范围。
User.rb
class User < ActiveRecord::Base
has_many :appointment_hosts,
:class_name => "Appointment",
:foreign_key => "appointment_hosts_id"
scope :repeat_customers, -> { includes(:appointment_hosts)
.where("appointment_hosts.status=?", "Complete")
.references(:appointment_hosts) }
end
Appointment.rb
class Appointment < ActiveRecord::Base
belongs_to :appointment_host, :class_name => "User", :foreign_key => "appointment_host_id"
end
错误
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: missing FROM-clause entry for table "appointment_hosts"
LINE 1: ...ents"."appointment_host_id" = "users"."id" WHERE (appointmen...