Be Careful Assigning to has_one Relations

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 https://rubyonrails.ba/single/be-careful-assigning-to-has_one-relations

Nezir Zahirovic

Contractor Ruby On Rails (8+ years) / MCPD .Net / C# / Asp.Net / CSS / SQL / (11 years)

related articles