0

There is something wrong with my associations.
I want that many VideoPost can refer to the same VideoInformation. I then thought that the foreign key should be in VideoPost so I started with the 2 models you can see below. But I can't access to @video_post.video_information (which seems to make sense since there is no association in VideoPost)
How should I do ? I'm a little confuse here

Thanks for any help !

My VideoPost model :

# 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

My VideoInformation model :

# 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
4

1 回答 1

1

你应该添加

belongs_to :video_information

进入 video_post.rb 因为当你定义关联时,你应该在两个模型中都这样做。

这是您可能想查看的一些信息

于 2012-10-30T19:23:32.500 回答