Rails模型范围有has_many错误

时间:2016-01-28 19:42:42

标签: sql ruby-on-rails-4 activerecord model scope

我想为仅托管标记为完成的约会的用户创建范围。

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...

0 个答案:

没有答案