我有两个模型。
文章
class Article < ActiveRecord::Base
attr_accessible :title, :body, :artist_ids
has_many :artists, :through => :artist_relationships
has_many :artist_relationships
end
艺术家.rb
class Artist < ActiveRecord::Base
attr_accessible :title, :body, :article_ids
has_many :articles, :through => :artist_relationships
has_many :artist_relationships
end
现在假设我Article
与两个有关系Artist
(例如迈克尔杰克逊,披头士......)
然后每个艺术家都有一些文章给他们。
我想要做的是通过它的..获取所有与 an 相关的文章。Article
artists
这是我尝试过的东西(不起作用....)
@article = Article.find(param[:id]) # an Article
@articles = Article.where(:artist_ids => @article.artist_ids) # get all articles of its related artists