0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

親要素と子要素を同時にbuildして親をsaveしたタイミングで子要素も作成する

Posted at

はじめに

この記事は2021年9月にまとめていた「細かいつまずいたことをメモしておく(9月編)をそれぞれ投稿した内容になります
解決方法が最新でない可能性もありますのでご了承ください

問題

@parent = Parent.build(parent_params)
@parent.build(child_params)

これでうまくいくかと思ったがうまくいかない
@parentbelongs_to child@childhas_one parentとなっている

解決方法

has_oneの関係のときはbuild_parentで行う

@parent.buid_child(child_paras)

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?