2011-08-17 51 views
3

我正在使用Ruby on Rails模型。我有两个模型属于两种不同的模式。两种模式有亲子关系。例如Ruby on Rails - 使用:包含在不同模式的模型中

class Group < ActiveRecord::Base 
    has_one :customer 
end 

class Customer < ActiveRecord::Base 
    establish_connection "schema2" 
end 

模型组在模式1中,客户在模式2中。如果我这样做是使用组下面的代码加载:

self.paginate(:all, :page => currentpage, :per_page => per_page, :include => :customer) 

我得到的错误 “schema1.Customer”是一个未定义的名称”,因为它正试图找到schema1代替SCHEMA2客户

我怎样才能改变这个查询(或这个:include)来表明这个客户在schema2中。我试图在group中以has_one的关系添加class_name作为 has_one :customer, class_name=>"Customer",但它不能解决问题,并且我得到相同的错误。

任何想法?

回答

0

你不行。您可以单独加载它们:

@groups = self.paginate(:all, :page => currentpage, :per_page => per_page) 
@customers = Customer.find(:all, :conditions => {:id => @groups.map(&:id)})