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 930063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:16:32+00:00 2026-05-15T20:16:32+00:00

I have a simple model: class User < ActiveRecord::Base has_and_belongs_to_many :roles end class Role

  • 0

I have a simple model:

class User < ActiveRecord::Base
   has_and_belongs_to_many :roles
end

class Role < ActiveRecord::Base
   has_and_belongs_to_many :users
end

I have created a simple join table:

class CreateUsersRoles < ActiveRecord::Migration
  def self.up
    create_table :users_roles, :id => false do |t|
      t.integer :user_id
      t.integer :role_id

      t.timestamps
    end
  end

  def self.down
    drop_table :users_roles
  end
end

After migration, shema.rb is following:

create_table "roles", :force => true do |t|
    t.string   "name"
    t.datetime "created_at"
    t.datetime "updated_at"
end

create_table "users", :force => true do |t|
    t.string   "login"
    t.string   "password"
    t.datetime "created_at"
    t.datetime "updated_at"
  end

create_table "users_roles", :id => false, :force => true do |t|
  t.integer  "user_id"
  t.integer  "role_id"
  t.datetime "created_at"
  t.datetime "updated_at"
end

The entries are presented here in the same order, as in “schema.rb”

I arranged fixtures in following way:

# roles.yml 
user:
  name: user

admin:
  name: admin

moderator:
  name: moderator

# users.yml
User1:
  login: User1
  password: User1
  roles: user

User2:
  login: User2
  password: User2
  roles: admin, moderator

User3:
  login: User3
  password: User3
  roles: moderator

And got a problem: on “rake db:fixtures:load” rails complains about name of a join table:

SQLite3::SQLException: no such table: roles_users: DELETE FROM “roles_users” WHERE 1=1

The question is – why it expects “roles_users”, while the table is “users_roles” ?

  • 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-15T20:16:33+00:00Added an answer on May 15, 2026 at 8:16 pm

    When Rails creates the association for the join table it expects the models to be in alphabetical order. Since r comes before u, it creates it as roles_users.

    I suggest that you rename the join table, alternatively, you can add :join_table => "users_roles" to both associations.

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

Sidebar

Related Questions

I have a simple model class Ad < ActiveRecord::Base has_many :ad_items end class AdItem
I have the following models to associate users with roles: class User < ActiveRecord::Base
I have a simple model called Party with a corresponding table called parties .
I want to implement a simple VersionedModel base model class for my app engine
Alright, I have a fairly simple design. class Update(models.Model): pub_date = models.DateField() title =
We have a simple domain model: Contact, TelephoneNumber and ContactRepository. Contact is entity, it
i have very simple problem. I need to create model, that represent element of
I'm relatively new to the Component Object Model specification - I have a simple
A simple question: I have a Model-View-Controller setup, with Models accessing a SQL database.
My needs are very simple: I have a Tip table to receive comments and

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.