I solved it a bit differently:
instance.id = Country.where(code: instance.code).first_or_create(instance.attributes).id
Not sure if it makes any difference with your sample above, but using instance.attributes makes it more generic as we don't have to explicitly mention each attribute.
instance.attributes
Thatβs neat! Yeah, this does seem simpler. Off the top of my head, I canβt think of any differences.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I solved it a bit differently:
Not sure if it makes any difference with your sample above, but using
instance.attributes
makes it more generic as we don't have to explicitly mention each attribute.Thatβs neat! Yeah, this does seem simpler. Off the top of my head, I canβt think of any differences.