After hours of googling for best practice, I came up here.
I have a new Foo object, and want to mass-assign thousands of bars to it, which I've pre-loaded:
@foo = Foo.create
@bars = Bar.find_all_by_some_attribute(:a)
What's the fastest way to do this? I've tried:
@foo.bars = @bars
@foo.bars << @bars
This results in thousands of insert queries being created.
Is there a Rails 6 (Insert_all) way to solve my issue or do I have to solve it with the "m2m_fast_insert" gem or hardcoded SQL?