[英]Ruby on Rails: User model association applications and migrations
I'm still fairly new to Ruby on Rails and I'm working with associations, such as if a table has_many :facts, or belongs_to :list, 我对Ruby on Rails还是很陌生,并且正在使用关联,例如表has_many:facts或belongs_to:list,
do we deal with users as well? 我们也要与用户打交道吗? for Users model:
对于用户模型:
has_many :lists
and then the list model should have 然后列表模型应该有
belongs_to :user
Now does this mean I need to create a new column in the table? 现在这是否意味着我需要在表中创建一个新列? Right now I only have email and password_digest.
现在,我只有电子邮件和password_digest。 Do I need to add a new migration to add a new column
list_id
. 我是否需要添加新迁移以添加新列
list_id
。 I already did rake db:migrate
. 我已经做了
rake db:migrate
。 Can I just simply add a column in the migration file? 我可以只在迁移文件中添加一列吗?
Thanks 谢谢
Yes, you must create a new column and if you already run the migration you must create a new one. 是的,您必须创建一个新列,如果已经运行迁移,则必须创建一个新列。
However, it's the list that must have the user_id
. 但是,该列表必须具有
user_id
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.