【发布时间】:2012-10-30 19:16:57
【问题描述】:
我的关联有问题。
我希望许多 VideoPost 可以引用相同的 VideoInformation。
然后我认为外键应该在 VideoPost 中,所以我从下面可以看到的 2 个模型开始。
但我无法访问@video_post.video_information(这似乎是有道理的,因为在 VideoPost 中没有关联)
我应该怎么做 ?我有点困惑
感谢您的帮助!
我的 VideoPost 模型:
# Table name: video_posts
#
# id :integer not null, primary key
# user_id :integer
# video_information_id :integer
# created_at :datetime not null
# updated_at :datetime not null
class VideoPost < ActiveRecord::Base
belongs_to :user
attr_accessible :video_information_id
end
我的 VideoInformation 模型:
# Table name: video_informations
#
# id :integer not null, primary key
# title :string(255)
# description :text
# keywords :text
# duration :integer
# video_url :string(255)
# thumbnail_small :string(255)
# thumbnail_large :string(255)
# created_at :datetime not null
# updated_at :datetime not null
class VideoInformation < ActiveRecord::Base
has_many :video_posts
end
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3 associations has-many