has_many through a habtm relationship in Rails
- by macek
I'm trying to define a has_many X, :through => Y where Y is a habtm relationship. Rails is throwing a fit about this. See comment in user model:
class User < ActiveRecord::Base
has_many :posts
# I want to display a list of all tags this user is involved in
has_many :tags, :through => :posts # ERROR
end
class Post < ActiveRecord::Base
has_and_belongs_to_many :tags
end
class Tag < ActiveRecord::Base
has_and_belongs_to_many :posts
end
What can I do to fix this?