Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/54.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 在Rails ActiveRecord中,联接不适用于具有名称空间的模型中的has_和属于多个_Ruby On Rails_Ruby On Rails 3_Activerecord - Fatal编程技术网

Ruby on rails 在Rails ActiveRecord中,联接不适用于具有名称空间的模型中的has_和属于多个

Ruby on rails 在Rails ActiveRecord中,联接不适用于具有名称空间的模型中的has_和属于多个,ruby-on-rails,ruby-on-rails-3,activerecord,Ruby On Rails,Ruby On Rails 3,Activerecord,我在一个名称空间中有两个模型,一个服务和一个讲师,这两个模型彼此之间有多对多的关系,通过has_和_-allown_-to_-many定义: class Scheduling::Service < ActiveRecord::Base has_and_belongs_to_many :instructors end class Scheduling::Instructor < ActiveRecord::Base attr_accessible :first_name,

我在一个名称空间中有两个模型,一个服务和一个讲师,这两个模型彼此之间有多对多的关系,通过has_和_-allown_-to_-many定义:

class Scheduling::Service < ActiveRecord::Base

  has_and_belongs_to_many :instructors
end

class Scheduling::Instructor < ActiveRecord::Base
  attr_accessible :first_name, :last_name
  has_many :instructor_availabilities

  scope :of_service, lambda { |service_id| joins(:services).where(:services => {:id => service_id})}

  has_and_belongs_to_many :services, :class_name => "Scheduling::Service"
end
class Scheduling::Service{:id=>service_id})
有且属于多个服务,:class\u name=>“Scheduling::Service”
结束
在_服务的范围内,我希望_服务返回与服务关联的所有讲师

但是,在运行此作用域时,我得到一个错误:

ActiveRecord::语句无效: PG::Error:错误:表“services”的子句条目中缺少 第1行:…“id”=“讲师服务”。“服务id”中的“服务”。。。 ^ :选择“调度讲师”。*从上的“调度讲师”内部加入“讲师服务” “讲师服务”。“讲师id”=“计划讲师”。“id” “调度服务”上的内部联接“调度服务”。“id”= “讲师服务”。“服务id”其中“服务”。“id”=107限制 一,


似乎出错的地方是它加入了一个名为instructors\u services的表(该表不存在),忽略了相关模型中的名称空间。它应该加入一个名为scheduling_instructors_services的表,该表与名称空间一致。

尝试将
:join_table=>“scheduling_instructors_services”
添加到您的关系中,如下所示:

has_and_belongs_to_many :instructors, :class_name => "Scheduling::Instructor", :join_table => 'scheduling_instructors_services'
has_and_belongs_to_many :services, :class_name => "Scheduling:: Service", :join_table => 'scheduling_instructors_services'
还有,不是吗


.where('instructors\u services.id'=>service\u id)

而不是


.where(:services=>{:id=>service_id})

在哪里:加入表格?