[英]database index in Active Record Associations
let's imagine this situation.I have a article
model and a sort
model,and they have a one-to-many association. 让我们想象一下这种情况。我有一个
article
模型和一个sort
模型,并且它们具有一对多的关联。
the article
migration is : article
迁移为:
create_table :articles do |t|
t.string :title
t.string :content
t.belongs_to :sort
t.timestamps
end
the sort
migration is : sort
迁移为:
create_table :sorts do |t|
t.string :title
t.timestamps
end
so the article
will be added a filed named sort_id
. 因此,将为该
article
添加一个名为sort_id
。
now,I want to add an index on the filed sort_id
in table articles
. 现在,我想在表格
articles
的文件sort_id
上添加索引。
whether I can realize as follow: 我是否可以实现如下:
add_index :articles, :sort, :unique => true
or 要么
add_index :articles, :sort_id, :unique => true
add_index :articles, :sort_id, :unique => true
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.