Rails复杂has_many和has_many通过

我有4个模型:抽屉,文件夹,FolderDocument和Document如下:

class Drawer < ActiveRecord::Base has_many :folders #Drawer has many folders end class Folder  :folder_documents, :conditions => proc { |v = nil| v ||= self.version "documents.active IS TRUE AND version = #{v}" }, :uniq => true end class FolderDocument < ActiveRecord::Base # Has a version attribute belongs_to :document belongs_to :folder end class Document  :folder_documents end 

我的问题是我不能创建一个

 has_many :documents, :through => :folders 

在类Drawer上作为proc条件(对于FolderDocument中的文档)不能计算为“version”是在Drawer的上下文中计算的,而不是中间文件夹关联。

有没有办法在不创建名为FolderVersion的Folder和FolderDocuments之间创建另一个模型的情况下这样做?

编辑:目标是获取属于当前版本的文件夹的所有文档(文件夹中的版本)。