database - 用户图像/配置文件字段-数据库规范化-社交网络-Grails

标签 database grails database-normalization

我应该规范用户profile_image_url链接和字段例如用户可以自定义个人资料的profile_background_color

拥有一个包含所有内容的单个User类。

class User {

  String profile_big_url
  String profile_thumb_url

  String profile_background_color
  String profile_text_color
  String profile_link_color
  String profile_sidebar_fill_color
  String profile_sidebar_border_color
  String profile_background_image_url
  String profile_background_tile

}

或三类
class User{

   Photo photo
   Profile profile

}

class Photo{
   User user   
   String profile_big_url
   String profile_thumb_url
}

class Profile{
   User user
   String profile_background_color
   String profile_text_color
   String profile_link_color
   String profile_sidebar_fill_color
   String profile_sidebar_border_color
   String profile_background_image_url
   String profile_background_tile
}

在规模,性能,修改方面哪个更好?

最佳答案

我不用担心。拆分表将生成较小的select,但是它们只是短字符串,因此提取比您需要的更多数据的开销很小。联接可能很昂贵,但同样,它们也很简单。

一种替代方法是将所有内容保留在一个表中,但是使用组件在代码中按逻辑将类拆分为三个类。参见http://grails.org/doc/latest/guide/5.%20Object%20Relational%20Mapping%20%28GORM%29.html#5.2.2%20Composition%20in%20GORM

关于database - 用户图像/配置文件字段-数据库规范化-社交网络-Grails,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6725404/

相关文章:

C# 恢复在线数据库

python - sqlalchemy 过滤多列

sql - 无损连接分解两个以上关系

MySQL:在一张表中引用多个表ID

sql - 无法连接到数据库 postgres pg_hba (OSX)

php - 警告 : mysqli_connect(): (HY000/1045): Access denied for user 'usr' @'localhost' (using password: YES)

grails - Intellij使用 “mvn grails:exec”而不是原始grails命令

grails - 访问 PUT 或 POST 请求的原始正文

Grails Paypal SDK 集成

sql - 将行非规范化为列是否可以提高 SQL Server 的性能?