Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5941849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:10:05+00:00 2026-05-22T16:10:05+00:00

**UPDATE: I found this: Active Record expects intermediate join tables to be named with

  • 0

**UPDATE: I found this:

“Active Record expects intermediate join tables to be named with a concatenation 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’ve been trying to do everything the same for them with regards to keywords. But adding a keyword to an image works fine while adding a keyword to a video doesn’t.

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

This works:

images_controller.rb

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

This:

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 for adding a keyword to an image, it correctly looks for “images_keywords” Why does it look for “keywords_videos” for videos???

What is different about the two?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T16:10:06+00:00Added an answer on May 22, 2026 at 4:10 pm

    When using has_and_belongs_to_many, the name of the join table needs to have the related models listed in alphabetical order, ie: keywords_videos not videos_keywords.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

12:18:55,541 INFO [UpdateChecker] New update(s) found: 2.0.0 [ http://ehcache.org/news.html] How do I suppress ehcache
[Update: I've found the API reference. The method used is below] <?php wp_delete_post( $postid,
All the documentation I've found so far is to update keys that are already
I found something that works with updating one field at here: http://www.karlrixon.co.uk/articles/sql/update-multiple-rows-with-different-values-and-a-single-sql-query/ UPDATE person
UPDATE - A comprehensive comparison, updated as of February 2015, can be found here:
Right guys, all autocomplete plugins and functions that I've found, they only update upon
UPDATE - Cause found! ... please read below & suggest the solution: While creating
I was reading about scoped mass assignment in Rails 3.1 (Edge). I found this
UPDATE: There's been a patch for this issue: https://github.com/collectiveidea/delayed_job/commit/023444424166ba2ce011bfe2d47954e79edf6798 UPDATE 2: For anyone running
I have this query: SELECT groups.name categories.name, categories.label FROM groups JOIN categories ON (categories.group1

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.