Postrgresql looks for invalid tables for many with Rails 3

** UPDATE: I found this:

"The active record expects staging join tables to be named with the join of the tables it joins in alphabetical order."

Sigh ... **

I have 3 models: images, videos and keywords. Images and videos look basically the same, and I tried to do the same for them with keywords. But adding a keyword to an image works great when adding a keyword to a video.

keyword.rb

has_and_belongs_to_many :cases
has_and_belongs_to_many :images
has_and_belongs_to_many :videos

video.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

It works:

images_controller.rb

@image.keywords << Keyword.new(:word => "test")

It:

videos_controller.rb

@video.keywords << Keyword.new(:word => "test")

Gives me this error:

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

When I check the console to add a keyword to the image, it correctly searches for "images_keywords". Why is he looking for "keywords_videos" for the video ???

?

+3
1

has_and_belongs_to_many , , : keywords_videos not videos_keywords.

+4

All Articles