Best approach to save user preferences?

Dharam Gollapudi picture Dharam Gollapudi · Jul 3, 2009 · Viewed 10.4k times · Source

I have seen two different approaches in saving user preferences.

APPROACH 1: Serializing them and saving in one of the column of USERS table

APPROACH 2: Creating a separate table PREFERENCES and make a has_many association from USERS to PREFERENCES.

Which one of the above two approaches would you prefer and what are the pros and cons of each over other?

Answer

Pesto picture Pesto · Jul 3, 2009

It's usually a good idea to favor normalization. The second solution keeps your models cleaner, allows for easy extensibility if new preferences are added, and keeps your tables uncluttered.