Set Attributes when Creating with .create_with
You can set attributes to be used when creating new records with .create_with
:
This can be particularly useful if you're doing a .find_or_create_by
and want to set some values only when creating:
This will find an author with name "Hashrocketeer". If we find an existing Author
, we won't change their post_count
. If we don't find an existing Author
, we'll create one with a post_count
of 0.
Read more in the docs
Tweet