ONE
-
has_many
可拥有多个对象 -
dependent: :destroy
级联删除
class Topic < ApplicationRecord
has_many :votes, dependent: :destroy
end
MORE
-
belongs_to
动词带s
,第三人称单数
class Vote < ApplicationRecord
belongs_to :topic
end
has_many
可拥有多个对象dependent: :destroy
级联删除class Topic < ApplicationRecord
has_many :votes, dependent: :destroy
end
belongs_to
动词带s
,第三人称单数class Vote < ApplicationRecord
belongs_to :topic
end
本文标题:rails-模型-一对多
本文链接:https://www.haomeiwen.com/subject/bjbktctx.html
网友评论