保存用户偏好的最佳方法? [英] Best approach to save user preferences?

查看:54
本文介绍了保存用户偏好的最佳方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我见过两种不同的保存用户偏好的方法.

I have seen two different approaches in saving user preferences.

方法 1:将它们序列化并保存在 USERS 表的一列中

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

方法 2:创建一个单独的表 PREFERENCES 并建立从 USERS 到 PREFERENCES 的 has_many 关联.

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?

推荐答案

支持规范化通常是个好主意.第二种解决方案使您的模型更简洁,如果添加了新的首选项,则可以轻松扩展,并使您的表格保持整洁.

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.

这篇关于保存用户偏好的最佳方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆