![](https://secure.gravatar.com/avatar/083e26025c846be789f5c0923185b2d0.png?default=mp&rating=pg&size=250)
Josh Cameron
Joined
10 Experience
0 Lessons Completed
0 Questions Solved
Activity
My understanding is that the method set_refferal_code that generates the code in the first place is ensuring that the code is unique. It will keep generating new codes, until it makes a unique one. I also found this article pretty helpful to learn about before and after methods. https://guides.rubyonrails.org/active_record_callbacks.html