So I have code in my application that appends to a has_many relation with the "<<" operator like so:
class BlogPost < ActiveRecord::Base
has_many :comments
def add_comment(content)
@new_comment = Comment.create(content)
self.comments << @new_comment
end
end
And it seems to work. I never really questioned it or wondered when it calls "save" (I guess I never had a strong understanding of when to call "save" to begin with).
However, it seems that the after_save
hook on comments doesn't get activated in my add_comment
function, which prompts me to ask:
How does the <<
operator work in activerecord and where can I read more about it?
Thanks