a1dert/lh-tickets-test — Issue #261: ActiveRecord::StatementInvalid in Demands#index when try to search requests
Author: a1dert
Created: 2011-11-30 12:01:37+00:00
State: open

Imported from lighthouse. Original ticket at: http://redtape.lighthouseapp.com/projects/59696/tickets/341. Created by Alexey Derkach - 2011-06-24T14:58:30Z

Steps to reproduce:

1. Go to Purchase page.
2. Search with query “p..” or another search phrase which end on ".."
3. Get an error.
4. Also happens on Time Off and Expense pages.

Expected: user should see search results.
Actual: server error.

Details:
Showing /var/www/apps/redtape/staging/releases/20110624085707/app/views/demands/index.html.erb where line #14 raised:
@@@
Mysql2::Error: Unknown column ‘last_changers_demands.archived’ in ‘on clause’: SELECT DISTINCT `demands`.id FROM `demands` INNER JOIN `users` `users_demands` ON `users_demands`.`id` = `demands`.`user_id` LEFT OUTER JOIN `days` ON `days`.`demand_id` = `demands`.`id` LEFT OUTER JOIN `expense_items` ON `expense_items`.`demand_id` = `demands`.`id` LEFT OUTER JOIN `time_off_types` ON `time_off_types`.`id` = `demands`.`time_off_type_id` LEFT OUTER JOIN `state_changes` ON `state_changes`.`demand_id` = `demands`.`id` LEFT OUTER JOIN `state_changes` `changers_demands_join` ON `demands`.`id` = `changers_demands_join`.`demand_id` LEFT OUTER JOIN `users` `changers_demands` ON `changers_demands`.`id` = `changers_demands_join`.`changer_id` LEFT OUTER JOIN `state_changes` `states_demands` ON `states_demands`.`demand_id` = `demands`.`id` AND `states_demands`.`archived` = 0 LEFT OUTER JOIN `state_changes` `last_changers_demands_join` ON `demands`.`id` = `last_changers_demands_join`.`demand_id` LEFT OUTER JOIN `users` `last_changers_demands` ON `last_changers_demands`.`archived` = 0 INNER JOIN `users` ON `demands`.user_id = `users`.id WHERE `demands`.`type` = ‘Purchase’ AND ((`users`.company_id = 2)) AND ((1 = 1 AND `demands`.type = ‘Purchase’) OR (1 = 1 AND `demands`.type = ‘TimeOff’) OR (1 = 1 AND `demands`.type = ‘Expense’)) AND (`demands`.user_id = 2) AND (CONCAT_WS(’ ‘, `users`.first_name, `users`.last_name, `demands`.notes) LIKE ’%%p..%%’) ORDER BY `demands`.created_at DESC LIMIT 10 OFFSET 0
@@@

Trace:
@@@
app/views/demands/index.html.erb:14:in `_app_views_demands_index_html_erb___1021433269_62730880_0'
@@@

Request:
@@@
{"model_type"=>"purchases",
"search"=>"p.."}
@@@

According to: [story 6671](https://tracker.anahoret.com/projects/44/stories/6671 "story 6671")