私は@postsという投稿の配列を持っています。ポストモデルhas_many:feelings:through =>:feelingships。Rails 3:has_many:through関係のデータベース呼び出し
投稿の配列を特定の感情の投稿に限定するにはどうすればよいですか?
私は以下のコードを試してみましたが、それは:(
@specific_feeling_posts = @posts.feeling.where(:feeling => "happy")
モデルに動作するはずです
class Post < ActiveRecord::Base
has_many :feelingships
has_many :feelings, :through => :feelingships
belongs_to :user
end
class Feeling < ActiveRecord::Base
has_many :feelingships
has_many :posts, :through => :feelingships
end
class Feelingship < ActiveRecord::Base
belongs_to :post
belongs_to :feeling
end