Has_one belongs_from the association autosave => true not saving

I have two models

Board
has_one    :pref, :autosave => true,  :dependent => :destroy

Pref

belongs_to :board

The pref object has the default values ​​set in the database, so no information should be used to create the object when creating the board. The identifier for the board is in the pref table.

Since: autosave => true, I thought that when creating and saving a new Board object, the pref object will be created and saved automatically.

This does not work this way, so I have to be a misunderstanding.

Is there a way to autosave the pref object while saving the board?

Thank you in advance

+3
source share
1 answer

autosave => trueshould not create an item for you. docs say :

true, , . false, .

callback pref board.

- :

after_create :create_pref

def create_pref
  pref.create!
end
+3

All Articles