Be Careful Assigning to has_one Relations
14-Feb-2019 2097
Most of the time, when building relationships between models, you typically use has_many and belongs_to. There are some circumstances where a has_one relationship is more appropriate.However, the behaviour of has_one has some quirks that make it a little trickier to deal with.When you assign a new instance of an associated model to its has_one model the existing instance is removed from the association and causes a permanent change to be written to the database. This happens whether the new model is valid or not.Read about this side effect of the generated .
Be Careful Assigning to has_one Relations #ruby #rubydeveloper #rubyonrails #Careful #Assigning #has_one #Relations https://rubyonrails.ba/link/be-careful-assigning-to-has_one-relations