[ rails ] through:, source:

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

Has many breeds

class Pet < ActiveRecord::Base
has_many :dogs
has_many :dog_breeds, :through => :dogs, :source => :breeds
end

:source look for an association called Dog.breeds

ref : http://stackoverflow.com/questions/4632408/need-help-to-understand-source-option-of-has-one-has-many-through-of-rails

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s