class Topic < ActiveRecord::Base
belongs_to :user, :counter_cache => true, :inverse_of => :topics
...
end
Ruby-Doc: If you are using a belongs_to on the join model, it is a good idea to set the :inverse_of option on the belongs_to, which will mean that the following example works correctly (where tags is a has_many :through association):
@post = Post.first
@tag = @post.tags.build :name => "ruby"
@tag.save
The last line ought to save the through record (a Taggable). This will only work if the :inverse_of is set:
class Taggable < ActiveRecord::Base
belongs_to :post
belongs_to :tag, :inverse_of => :taggings
end
还是不太明白。。。