given parent.list is a has_many of Child, I've found that if I do this:
child = Child.new(...)
parent.list << child
rails will select * all of parent.list before doing the insert of the
new child (if parent.list isn't already loaded). This is -bad- because
my parent.list is huge.
This ensures a single insert and also throws an exception if any DB
constraints are violated, thus ensuring any encompassing transactions
and/or top level logging is handled.
is this generally the right thing to do with rails? I'm a noob coming
from enterprise development in other languages.
Or is there some other magic way to add to parent.list with the above
kind behavior?
given parent.list is a has_many of Child, I've found that if I do this:
child = Child.new(...)
parent.list << child
rails will select * all of parent.list before doing the insert of the
new child (if parent.list isn't already loaded). This is -bad- because
my parent.list is huge.
Cool. Thanks. I'll use that. In one case though, I have to create a new
child that "belongs_to" 2 different kinds of parents. So for that, I'll
have to use the build method to make it happen in a single insert.