Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


column_names sometimes doesn't fetch all columns #514

wants to merge 1 commit into from

3 participants


changed AR base#column_names, now instance variable @column_names ever assigned



Can you try and explain more clearly in what situation do you not get all the column names? There is a method called "reset_column_information" that you can call to bust the column cache. You usually use this method in a migration to work with a column just created/altered before working on it.


Hi Asanghi,
I don't get the column_names directly, the situation ist:
I have a model composition, which is associated with composer(s) and work(s)
through join tables to person and work, both have synonyms, stored in corresponding tables

now I have some scopes for sorting, one of them is following:

scope :sorted_by_title_and_composer, lambda{|direction| joins(:has_composer,:has_title)
.includes(:has_composer => [:synonyms], :has_title => [:synonyms])
.order(" #{direction}, #{direction}")}

this scope is used by a ajax search in following line:

.where(" LIKE ? OR people.surname LIKE ? OR people.prename LIKE ? OR person_synonyms.synonym LIKE ? OR work_synonyms.synonym LIKE ?",'%'+search+'%','%'+search+'%','%'+search+'%','%'+search+'%','%'+search+'%')

trhat's the reason why I need the includes, hence I must also search the synonyms

if I use includes for eager loading, then in the index view I have the error that a column doesn't exist.

the following work, but is much slower:

scope :sorted_by_title_and_composer, lambda{|direction| joins(:has_composer => [:synonyms], :has_title => [:synonyms])
.order(" #{direction}, #{direction}")}

this failure exist only in production mode, and other scopes using includes are also pertained,
there I use the lambda fix


Please provide a test to exercise the bug you're encountering. When you've added the test, please reopen this pull request, or send a new one. Thanks!

@tenderlove tenderlove closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 11, 2011
This page is out of date. Refresh to see the latest.
Showing with 2 additions and 1 deletion.
  1. +2 −1  activerecord/lib/active_record/base.rb
3  activerecord/lib/active_record/base.rb
@@ -701,7 +701,8 @@ def columns_hash
# Returns an array of column names as strings.
def column_names
- @column_names ||= { |column| }
+ @column_names = { |column| }
+ # @column_names ||= { |column| }
# Returns an array of column objects where the primary id, all columns ending in "_id" or "_count",
Something went wrong with that request. Please try again.