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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:09:27+00:00 2026-06-08T18:09:27+00:00

I’m trying to delete from a join table I made and I’m getting a

  • 0

I’m trying to delete from a join table I made and I’m getting a weird error I cant figure out.

Here are my models

class ArticlesUser < ActiveRecord::Base
 # attr_accessible :title, :body
 belongs_to :user
 belongs_to :article
end

class Article < ActiveRecord::Base
 attr_accessible :title
 belongs_to :user

 has_many :articles_users
 has_many :likes, :through => :articles_users, :class_name => 'User', :source => :user    
end

class User < ActiveRecord::Base 
 has_many :articles, :order => 'id DESC'
 has_and_belongs_to_many :badges

 has_many :articles_users
 has_many :likes, :through => :articles_users, :class_name => 'Article', :source => :article
end

Testing in the Rails Console you can see the error:

> a = Article.find(13) 
> a.articles_users #works fine, returns an array of users who "like" the article
> a.articles_users.where(user_id: 3) #works as well
> a.articles_users.where(user_id: 3).first.destroy #this is where the error is thrown!

Here is there error:

 ActiveRecord::StatementInvalid: Mysql2::Error: Unknown column 'articles_users.' in 'where clause': DELETE FROM `articles_users` WHERE `articles_users`.`` = NULL

Why does it seem to be completely ignoring the where hash? Please help me with this I’ve spent hours today trying to figure it out.

Thanks!

Edit:

The articles_users table has 2 columns: article_id and user_id

Edit:

This is copy and pasted from the console:

1.9.3p194 :004 > a.articles_users.where(user_id: 3).first
ArticlesUser Load (0.7ms)  SELECT `articles_users`.* FROM `articles_users` WHERE    `articles_users`.`article_id` = 13 AND `articles_users`.`user_id` = 3 LIMIT 1
=> #<ArticlesUser user_id: 3, article_id: 13> 
  • 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-08T18:09:28+00:00Added an answer on June 8, 2026 at 6:09 pm

    I tried and reproduced your issue.

    From Your output it seems you don’t have a id column in ArticlesUser
    which is the cause if issue.

    => #<ArticlesUser user_id: 3, article_id: 13> 
    

    I tried adding id column to the table and it worked like charm.
    Created a new migration and add it

     add_column :articles_users, :id, :primary_key
    

    When you destroy a record rails uses its id as a reference to delete it from database.

    Check example.

     DELETE FROM `articles_users` WHERE `articles_users`.`id` = 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.