Is it just me, or is it crazy that directly saving a model created via #build
or #new
on a has_many :through
relationship does not create a join model?
See the migrations.rb
, models.rb
& test_irb_session.txt
files below for a concise example of the problem.
This kind of technique is used commonly on nested controllers, and it would work fine for a plain belongs_to
or has_many
associations. In fact, this behaviour would stop me from using any RESTful controller helpers, like resource_controller.
Is there are way to make it work? Or do I need to look for alternatives, like the below?
s = Subject.first
a = Article.new
# this will save the new article record and create the join model
s.articles << a
The only other place I've found mentioning is this recent bug report