...

/

Validations Don’t Provide Data Integrity

Validations Don’t Provide Data Integrity

Learn about data integrity via validations in our Rails application.

Now that we’ve had an intro to models, a full discussion of business logic, and a journey through database design, we want to cap off the models discussion by talking about validations, callbacks, scopes, and testing. Then, we can see an end-to-end example of how this all fits together, which will paint a complete picture of the sustainable approach to business logic.

We’ve made the point several times to keep business logic out of Active Records, but we’ve also heavily implied that we should be using validations, which are a form of business logic. We also talked briefly about managing queries, along with a handful of references to avoid callbacks. This chapter will cover all of these topics.

Let’s start with validations, which are great at user experience management but not so great at data integrity.

Do validations provide data integrity?

When we discussed database modeling earlier in the course, we spent a fair bit of time talking about how to enforce the types of data that get stored, in particular, ensuring that only valid values ...