**更新:我发现了这个:
活动记录要求中间联接表的名称由它联接的表串联而成,按字母顺序排列
Sigh... **
我有3个模型:图像,视频和关键字。图片和视频看起来基本上是一样的,我一直在努力为它们做同样的关键词。但是,在图像中添加关键字效果良好,而在视频中添加关键字则不然。
关键字.rb
has_and_belongs_to_many :cases
has_and_belongs_to_many :images
has_and_belongs_to_many :videos
视频.rb
has_and_belongs_to_many :keywords
image.rb
has_and_belongs_to_many :keywords
schema.rb
create_table "images_keywords", :id => false, :force => true do |t|
t.integer "image_id"
t.integer "keyword_id"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "videos_keywords", :id => false, :force => true do |t|
t.integer "video_id"
t.integer "keyword_id"
t.datetime "created_at"
t.datetime "updated_at"
end
这样可以:
images_controller.rb
@image.keywords << Keyword.new(:word => "test")
这个:
视频_控制器.rb
@video.keywords << Keyword.new(:word => "test")
出现以下错误:
ActiveRecord::StatementInvalid in VideosController#create
PGError: ERROR: relation "keywords_videos" does not exist
LINE 4: WHERE a.attrelid = "keywords_videos" ::regclas...
^
: SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull
FROM pg_attribute a LEFT JOIN pg_attrdef d
ON a.attrelid = d.adrelid AND a.attnum = d.adnum
WHERE a.attrelid = "keywords_videos" ::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum
当我检查控制台是否向图像添加关键字时,它会正确地查找“images_keywords”。为什么它会为视频查找“keywords_videos”???
两者有什么不同?