什么是和使用数据类型的例子 - 引用 [英] What is and examples of using data type - References
问题描述
我想知道数据类型参考以及一些关于如何/为什么在网站上使用的示例。如果他们是使用Ruby-on-Rails时的区别,我标记它,以防万一。我是一个新的编程,它将帮助极大地解释一切在外行的条款。
感谢帮助我的麻烦,谢谢。
<我想在迁移中指的是
t.references:associated_model
的解释方案?
假设有两个模型:Post和Author。
; ActiveRecord :: Base
belongs_to:author
end
class Author< ActiveRecord :: Base
has_many:posts
end
您的迁移包含: / p>
create_table:posts do | t |
t.references:author
end
在 posts
表中使用整数
数据类型<$ p>创建$ c> author_id >
在迁移中, t.belongs_to
是 t.references的一个别名
并匹配用于在模型中设置关联的命名。
i wanted to know about the data type references and some examples of how/why it would be used on a website. If their is a difference when using Ruby-on-Rails, i tagged it just in case. I am new at programming and it would help tremendously to explain everything in layman's terms so i can slowly build my way up to being a computer wiz.
Appreciate the trouble in helping me, thanks.
I'm taking a guess that you're referring to t.references :associated_model
in a migration?
Suppose two models, Post and Author.
class Post < ActiveRecord::Base
belongs_to :author
end
class Author < ActiveRecord::Base
has_many :posts
end
Your migration contains:
create_table :posts do |t|
t.references :author
end
This will create the author_id
column on the posts
table with the integer
datatype.
In migrations, t.belongs_to
is an alias for t.references
and matches the naming used to set up the associations in your models.
这篇关于什么是和使用数据类型的例子 - 引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!