I have Table1 who has a has_many relationship with Table2
# app/models/table1.rb
class Table1 < ApplicationRecord
.
.
.
has_many :table2_relations, class_name: Table2, foreign_key: instance2_id
The belongs_to relationship in Table2 is marked as required:
# app/models/table2.rb
class Table2 < ApplicationRecord
.
.
.
belongs_to instance2, class_name: Table1, required: true
My ActiveAdmin file is :
ActiveAdmin.register Table1 do
.
.
.
controller do
def create
.
.
.
end
I have an ActiveAdmin page to create a new Table1 that also include table2_relations but since belongs_to required is true, when super is called, it will do all insert statements first then commit, causing a instance2 does not exist error because the creation of Table1 has not commited yet before creation of table2_relations is committed. The creation of table2_relations is only possible in the context of updating. How can I make the creation of Table1 committed first before creation of table2_relations? Thank you