我应该规范用户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/