Parent Child - Transaction Issue

Hi guys,

I was trying to create a record in both the parent and child tables (1
to 1
relationship). By default when you call it’s not invoked in
transaction mode, and I’m trying to avoid parent record is created
the child record (due to validation error in child).

I wanted to save both parent and child in transaction mode:

parent =
child = parent.build_child

Parent.transaction do! # parent created, child validation check failed but
no exception thrown! # exception triggered for validation error, transaction
rolled back

The problem is because parent was initially successfully created,
paret.new_record? returns true, even though it was rolled back later on,
subsequent attempt to save will not insert the parent record.

Am I missing something here? Please help to shed some lights? Thanks!