Ruby on Rails - 在不同模式的模型中使用:include
我正在使用 Ruby on Rails 模型。我有两个模型属于两个不同的模式。两个模型具有父子关系。例如,
class Group < ActiveRecord::Base
has_one :customer
end
class Customer < ActiveRecord::Base
establish_connection "schema2"
end
模型组位于 schema1 中,而客户位于 schema2 中。如果我使用以下代码执行此操作来加载组:
self.paginate(:all, :page => currentpage, :per_page => per_page, :include => :customer)
我收到错误 “schema1.Customer”是一个未定义的名称”,因为它试图在 schema1 而不是 schema2 中查找 Customer。
我如何更改此查询(或此:include)以指示客户位于 schema2 中。我尝试在 has_one 中添加 class_name组中的关系为 has_one :customer, class_name=>"Customer"
,但这并不能解决问题,我得到了同样的错误。
有什么想法吗?
I am working with Ruby on Rails models. I have two models belonging to two different schemas. Two models have parent child relationship. e.g
class Group < ActiveRecord::Base
has_one :customer
end
class Customer < ActiveRecord::Base
establish_connection "schema2"
end
Model Group is in schema1 and customer is in schema2. If I do this to load Groups using following code:
self.paginate(:all, :page => currentpage, :per_page => per_page, :include => :customer)
I get the error
"schema1.Customer" is an undefined name" as it is trying to find Customer in schema1 instead of schema2.
How can I change this query (or this :include) to indicate that customer is in schema2. I tried to add class_name in has_one relationship in Group ashas_one :customer, class_name=>"Customer"
, but it doesn't solve the problem, and I get the same error.
Any Ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你不能。您只能单独加载它们:
You can't. You can load them only separate: