We have a users table with accounts and patients tables, that both belong_to :user. We eager load the accounts and patients table for a given user record like this:
user = User.includes([:accounts, :patients]).find_by(email: "[email protected]")
...and this works fine. If we want to add a record to a user's accounts table in a manner that both A) commits the new record to the database and B) automatically adds the new record to the eager-loaded array, we execute this:
user.accounts.create(:name => "test name", :customer => "test customer")
...and this also works fine. However, how do we destroy a specific record in such a way that both A) removes the record from the database and B) automatically removes the record from the eager-loaded array? We have tried simply using something akin to:
account1 = user.accounts.first
account1.destroy
...and this does delete the record from the database, but does not automatically remove it from the eager-loaded array. How do we destroy a record in such a manner that it both removes it from the database and removes it from the eager-loaded array?