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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:06:06+00:00 2026-06-18T10:06:06+00:00

Hello I’m making a form for establishing many-to-many relationship between two models using this

  • 0

Hello I’m making a form for establishing many-to-many relationship between two models

using this solution

I Have Three Model

Artist, Article, ArtistRelationship.

This is Artist Model.

 class Artist < ActiveRecord::Base
   default_scope order('created_at DESC')

   attr_accessible :body_en, :body_kr, :title_en, :title_kr

   has_many :articles, :through => :artist_relationships
   has_many :artist_relationships
 end

And this is Article Model.

 class Article < ActiveRecord::Base
    default_scope order('created_at DESC')

    attr_accessible :title, :body, :date

    has_many :artists, :through => :artist_relationships
    has_many :artist_relationships

 end

And this is ArtistRelationship Model

 class ArtistRelationship < ActiveRecord::Base
   default_scope order('created_at DESC')

   attr_accessible :article_id, :artist_id

   belongs_to :artist
   belongs_to :article

 end

Now I have a form for an article to set the artists.

 <%= form_for [:admin, article] do |f| %>
   .....
     <% Artist.all.each do |artist| %>
        <div>
           <%= label_tag :artist_ids, artist.title_kr %>
           <%= check_box_tag :artist_ids, artist.id, article.artists.include?(artist), :name => 'article[artist_ids][]' %>
        </div>
     <% end %>

The error come from here

 article.artists.include?(artist)

It raises these error

Mysql2::Error: Column ‘created_at’ in order clause is ambiguous: SELECT 1 AS one FROM artists INNER JOIN artist_relationships ON artists.id = artist_relationships.artist_id WHERE artist_relationships.article_id = 1 AND artists.id = 2 ORDER BY created_at DESC LIMIT 1

I can’t get what it means..

And weired thing occurs when I use pry to debug right above the code

 <%= check_box_tag :artist_ids, artist.id, article.artists.include?(artist), :name => 'article[artist_ids][]' %>

in pry console when I directly call article.artists.include?(artist)

It raise same error as I expected. but

When I call article.artists it returns an array of artist belongs to that article

then I call article.artists.include?(artist) again. I works fine.

What’s the problem of this?

  • 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-18T10:06:08+00:00Added an answer on June 18, 2026 at 10:06 am

    in all your default scope, include the tableized version of the class

    # article.rb
    default_scope order('articles.created_at DESC')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I have like this 2 tables class User public int UserId{get;set;} { ....
Hello everyone and thanks for your help! I currently have this program that renames
Hello I'm making RSS reader and I'm using DOM. Now I stuck, trying to
Hello At my form I create TFrame at runtime. At this frame I create
Hello I am using this code to get the data I need from 5
Hello! I have this trouble: I'm searching reports by date and in html view
Hello i have this scenario currently i have 3 default sections. A , B
Hello everybody i have asp.net mvc4 application where i made countdown something like this:
Hello the problem I'm having is this, I have a landing page (event.php) that
Hello I have a call like this list of digits(436,L). How can I reverse

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.