Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

column_names sometimes doesn't fetch all columns #514

wants to merge 1 commit into


None yet
3 participants

LeFnord commented May 11, 2011

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



asanghi commented May 11, 2011

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.

LeFnord commented May 11, 2011

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("works.name #{direction}, people.name #{direction}")}

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

.where("works.name 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("works.name #{direction}, people.name #{direction}")}

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


tenderlove commented May 11, 2011

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 May 11, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment