Note that there are some explanatory texts on larger screens.

plurals
  1. POActiveRecord::StatementInvalid: Mysql2::Error: Table doesn't exist
    primarykey
    data
    text
    <p>I'm trying to create simple internal messaging service for that i have used devise for authentication so i have users table. I have created a messages table for messages and a join table called messages_users. I want to use has_many through association so my associations are like this:-</p> <p>user.rb :-</p> <pre><code>has_many :sent_messages, class_name: "Message", foreign_key: "user_id" has_many :message_users has_many :received_messages, through: :message_users, source: :message </code></pre> <p>message.rb:-</p> <pre><code>belongs_to :user has_many :message_users has_many :receivers, through: :message_users, source: :user </code></pre> <p>message_user.rb :-</p> <pre><code>class MessageUser &lt; ActiveRecord::Base belongs_to :user belongs_to :message end </code></pre> <p>and schema.rb :-</p> <pre><code>ActiveRecord::Schema.define(version: 20130912100741) do create_table "messages", force: true do |t| t.text "subject" t.text "body", limit: 2147483647 t.integer "user_id" t.datetime "created_at" t.datetime "updated_at" end create_table "messages_users", id: false, force: true do |t| t.integer "user_id", null: false t.integer "message_id", null: false end add_index "messages_users", ["message_id"], name: "index_messages_users_on_message_id", using: :btree add_index "messages_users", ["user_id"], name: "index_messages_users_on_user_id", using: :btree create_table "users", force: true do |t| t.string "email", default: "", null: false t.string "encrypted_password", default: "", null: false t.string "reset_password_token" t.datetime "reset_password_sent_at" t.datetime "remember_created_at" t.integer "sign_in_count", default: 0 t.datetime "current_sign_in_at" t.datetime "last_sign_in_at" t.string "current_sign_in_ip" t.string "last_sign_in_ip" t.string "confirmation_token" t.datetime "confirmed_at" t.datetime "confirmation_sent_at" t.string "unconfirmed_email" t.integer "failed_attempts", default: 0 t.string "unlock_token" t.datetime "locked_at" t.string "authentication_token" t.datetime "created_at" t.datetime "updated_at" t.string "provider" t.string "uid" t.string "name" end add_index "users", ["authentication_token"], name: "index_users_on_authentication_token", unique: true, using: :btree add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, using: :btree add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree add_index "users", ["unlock_token"], name: "index_users_on_unlock_token", unique: true, using: :btree end </code></pre> <p>It works fine when i use user_object.sent_messages but when i use user_object.received_messages it gives me <strong>Mysql2::Error: Table 'to_do.message_users' doesn't exist: SHOW FULL FIELDS FROM message_users ActiveRecord::StatementInvalid: Mysql2::Error: Table 'to_do.message_users' doesn't exist</strong> error. I want to use has_many through only and not habtm. There were a couple of questions here on stackoverflow but none of them solved my issue so any suggestions?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload