Belongs_To Presence Validation
Greetings Folks, In this blog, we're gonna see about the belongs to presence validation, to make sure that it doesn't become a problem for you. Belongs to presence validation is a change in Rails 5.0, It didn't exist before that. Prior to Rails 5.0 an object that had a belongs to relationship could be saved to the database even if it didn't have a parent object associated with it. That is the belongs to relationship was not required To be present. Now, starting in Rails 5, the belongs to relationship is not optional by default, what happens behind the scenes is that when we declare a belongs to, active record adds a validation on the object for the related objects presence... The parent object. So if we have our page that means, that the page won't save to the database. Unless we have a subject associated with it. Now we're gonna talk more abou...