I have a situation where children are built but not saved, and are then being used in the view with references to the parent. This leads to extensive use of rails record caching. I'd like to have the parent 'eager loaded' with the unsaved children records.
class Parent < ActiveRecord::Base
has_many :children
def make_children
loop..
children_array << children.build(...)
end
end
end
Then in the view (note that 'child' isn't saved to DB):
children_array.each do |child|
# What's the best way to optimise this so it doesn't
# keep selecting parent albeit from the cache?
child.parent
end