How to save new objects into an arrayList?

Why does ActiveRecord save association objects to database immediately on assignment, and not delay it till a save is called on the model?

  • post = Post.create post.comments = Comment.create # new comment will immediately be reflected in db post.save

  • Answer:

    Because you saved a comment which has the foreign key.

Milan Dobrota at Quora Visit the source

Was this solution helpful to you?

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.