2011-08-17 52 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)})