Rails has_one、包含或加入
我想知道在 Rails 3 中设置此数据库结构的最佳方法是什么...
我有一个 users 表和一个 user_profiles 表。 users_table 包含“姓名、电子邮件、密码、登录计数”; user_profiles 表包含“头像、地址”其他信息等...
当我检索用户时,我还需要带回他们的个人资料数据,当用户编辑他们的个人资料时,他们正在编辑两个表中的数据...
什么是最好的如何建立这些表之间的关系?
has_one 与Belongs_to、include 或join.... 还是有更好或标准的方法?你会怎么办?
感谢您的帮助! :)
I was wondering whats the best way to set up this DB structure in Rails 3...
I have a users table and a user_profiles table.
The users_table contains 'name, email, pass, login_count'; the user_profiles table contains 'avatar, address' other info etc...
When I retrieve a user I need to bring back their profile data as well and when a user edits their profile they are editing data from both tables...
Whats the best way to set up the relationships between these tables?
has_one with belongs_to, include or join.... or is there a better or standard way? What would you do?
Thanks for the help! :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
has_one
和belongs_to
适合您。浏览此 Railscast 以更好地理解它。has_one
andbelongs_to
for you. Go through this rails cast to better understand it.