本文介绍了扶手:身份验证的一种模式和个人资料信息,或2个独立的模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在很多教程(特别是身份验证),喇叭说把用户认证和配置文件信息在用户名为同一表(模型)。

In many tutorials (especially for authentication), speakers say to put user authentication and profile information in the same table (model) called User.

我的问题很简单:它是安全的,把一切都放在一个表? (奖金:这是最好的做法)

我宁愿建议独立的身份验证信息(电子邮件,密码,盐,...)和配置文件信息(姓,名,出生当天,位置,性别,...)两种型号:用户(认证)和档案,并通过HAS_ONE / belongs_to的关联链接的模型。

I would rather suggest to separate authentication information (email, password, salt,...) and profile information (first name, last name, birth day, location, gender,...) in two models: User (for authentication) and Profile, and linking models by has_one/belongs_to associations.

难道我错了吗?你有什么建议吗?

感谢。

推荐答案

如果你想按照你应该分开表。但是,有时它是不是最好的选择...例如,如果你的表用户电子邮件密码(用于认证)和名称。我不会创建一个简介表只是保存在名称,对吧?

If you want to follow database normalisations you should separate the tables. However, sometimes it is not the best option... For example, if your table users has just email, password (for authentication) and name. I won't create a profile table just to store the name, right?

所以,这将取决于你的需求,让您的设计决策....

So, it will depend on your requirements to make your design decisions....

我发现this有趣的帖子一下吧,在那里@D罗迪斯解释这三种方法的一些优点和缺点:中的用户存储用户信息表存储用户配置文件USER_PROFILE表1-1的关系,用户存储用户配置文件,如表的属性和值

I found this interesting post about it, where @D Roddis explain some advantages and disadvantages about three different approaches: Storing User Profile in Users Table, Storing User Profile in User_Profile Table 1-1 relationship to users and Storing User Profile as properties and values in tables.

我希望它可以帮助...

I hope it helps...

这篇关于扶手:身份验证的一种模式和个人资料信息,或2个独立的模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-22 13:19