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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:48:51+00:00 2026-06-01T03:48:51+00:00

I have 2 models – Teacher and Subject . A want to connect them

  • 0

I have 2 models – Teacher and Subject. A want to connect them via Join table with name Qualification.

It looks like i do something wrong:

class Teacher < ActiveRecord::Base
  has_and_belongs_to_many :subjects, :join_table => "Qualification"
end

class Subject < ActiveRecord::Base 
  has_and_belongs_to_many :teachers, :join_table => "Qualification"
end

My migration:

class CreateQualificationJoinTable < ActiveRecord::Migration
  def change
    create_table :qualification, :id => false do |t|
      t.integer :subject_id
      t.integer :teacher_id
    end
    add_index :qualification, :subject_id
    add_index :qualification, :teacher_id
  end
end

When i open rails console and print, for example

ruby-1.9.3-head :013 > Qualification

I get this:

NameError: uninitialized constant Qualification
    from (irb):13
    from /Users/serg/.rvm/gems/ruby-1.9.3-head/gems/railties-3.2.0/lib/rails/commands/console.rb:47:in `start'
    from /Users/serg/.rvm/gems/ruby-1.9.3-head/gems/railties-3.2.0/lib/rails/commands/console.rb:8:in `start'
    from /Users/serg/.rvm/gems/ruby-1.9.3-head/gems/railties-3.2.0/lib/rails/commands.rb:41:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

What is wrong?

  • 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-06-01T03:48:53+00:00Added an answer on June 1, 2026 at 3:48 am

    First, creating the table in a migration doesn’t define your model. You have to create a Qualification model in app/models/qualification.rb:

    class Qualification < ActiveRecord::Base
      belongs_to :subjects
      belongs_to :teachers
    end
    

    Second, if you’re using Rails 3, throw out has_and_belongs_to_many and use has_many :through:

    class Teacher < ActiveRecord::Base
      has_many :qualifications
      has_many :subjects, :through => :qualifications
    end
    
    class Subject < ActiveRecord::Base 
      has_many :qualifications
      has_many :teachers, :through => :qualifications
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have models that looks like search.rb: id eg: 101 name eg: San Francisco
So, say I have models like this: class Foo(Model): name = CharField(max_length=200) def latest_comment(self):
I have models like this class Blog(models.Model): name = models.CharField(max_length=100) tagline = models.TextField() def
I have models of my tables and would like to do a join using
I have models with many to many relationships like this: class Contact(models.Model): name =
Hey, I have models like this: class Galleries(models.Model): creation_date = models.DateTimeField() name = models.CharField(max_length=255,
I have models like this: class Vendor(models.Model): title = models.CharField() class Product(models.Model): ... vendor
I have models like this: class IdfPracownicy(models.Model): nazwa = models.CharField(max_length=100) class IdfPracaOpinie(models.Model): nazwa =
I have that situation: I have models Item, Region and Country. class Item(models.Model): name
I use flask with flask-peewee and wtfpeewee. So, I have models like that: class

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.