理解:通过Rails的has_one / has_many的源选项
请帮助我理解:source has_one/has_many :through :source选项has_one/has_many :through关联。  Rails API的解释对我来说毫无意义。 
“指定
has_many:through => :queries使用的源关联名,has_many:through => :querieshas_many :subscribers, :through => :subscriptions将在Subscription查找:subscribers或:subscriber:subscribers:subscriber,除非a:source被给出。“
 有时候,你想为不同的关联使用不同的名字。 如果要用于模型上关联的名称与:through模型上的关联不相同,则可以使用:source来指定它。 
 我不认为上面的段落比文档中的更清楚,所以这里是一个例子。 假设我们有三个模型, Pet , Dog和Dog::Breed 。 
 class Pet < ActiveRecord::Base has_many :dogs end class Dog < ActiveRecord::Base belongs_to :pet has_many :breeds end class Dog::Breed < ActiveRecord::Base belongs_to :dog end 
 在这种情况下,我们select命名空间Dog::Breed ,因为我们想要访问Dog.find(123).breeds作为一个很好和方便的关联。 
 现在,如果我们现在想在Pet上创build一个has_many :dog_breeds, :through => :dogs关联,我们突然有一个问题。  Rails将无法在Dog上find:dog_breeds关联,所以Rails不可能知道要使用哪个 Dog关联。 input:source : 
 class Pet < ActiveRecord::Base has_many :dogs has_many :dog_breeds, :through => :dogs, :source => :breeds end 
 使用:source ,我们告诉Rails 寻找一个叫做Dog模型 (如Dog模型 ),并使用它。 
让我展开这个例子:
 class User has_many :subscriptions has_many :newsletters, :through => :subscriptions end class Newsletter has_many :subscriptions has_many :users, :through => :subscriptions end class Subscription belongs_to :newsletter belongs_to :user end 
 通过这个代码,你可以做一些类似于Newsletter.find(id).users来获得通讯订阅者列表。 但是,如果您希望更清楚并能够inputNewsletter.find(id).subscribers ,则必须将“新闻”类更改为: 
 class Newsletter has_many :subscriptions has_many :subscribers, :through => :subscriptions, :source => :user end 
 您正在将users关联重命名为subscribers 。 如果你不提供:source ,那么Rails将在Subscription类中查找一个叫subscriber的关联。 您必须告诉它使用Subscription类中的user关联来创build订阅者列表。 
最简单的答案是:
中间是表中关系的名称。