Disabling auto save through the has_many association - Disabling an ActiveRecord object from a session

The default behavior for Ruby on Rails is to save changes made to collection associations. Is there a way to change this behavior so that I can modify the collections in memory without making any changes to the database.

So, if I have two classes:

class Project < ActiveRecord::Base
  has_many :tasks

class Task < ActiveRecord::Base
  belongs_to :project

and write some code:

Project.tasks.clear
Project.tasks << task1
Project.tasks << task2

then it automatically deletes all tasks related to the project and automatically writes the changes to db.

, . , Project.tasks.build(), , , , , . . . , Project.tasks.clear db.

java-, Hibernate, .

+5
1

task_ids?

:

Project.tasks_ids = []
Project.tasks_ids << task1.id
Project.tasks_ids << task2.id

, , , Google, , .

+2

All Articles