aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2018-02-26 14:27:22 +0100
committerJohan Van Ryseghem2018-03-07 13:19:41 +0100
commitf43442404d37cfb04b012c73c24b1dc4bf01168d (patch)
tree809ca8f815d73a284edc6b9a84aab05472a9bce9
parent0baeff6da40e5f631ef32ebe553f881dfb31a0c2 (diff)
downloadchouette-core-f43442404d37cfb04b012c73c24b1dc4bf01168d.tar.bz2
AutocompleteLinesController: Include company name in filter
The `#display_name` used in the drop-down on `ReferentialVehicleJourneys#index` includes the line's company name. Include this as a field to filter lines by. Additionally, use `%query%` filtering everywhere. It's going to be slower, but will produce the same behaviour for all fields for consistency and is easier for searching by company name when you might want to filter by a term in the middle of the name. Refs #5889
-rw-r--r--app/controllers/autocomplete_lines_controller.rb8
1 files changed, 5 insertions, 3 deletions
diff --git a/app/controllers/autocomplete_lines_controller.rb b/app/controllers/autocomplete_lines_controller.rb
index 945736ab9..0202ea054 100644
--- a/app/controllers/autocomplete_lines_controller.rb
+++ b/app/controllers/autocomplete_lines_controller.rb
@@ -9,13 +9,15 @@ class AutocompleteLinesController < ChouetteController
@lines = referential.line_referential.lines
filter = <<~SQL
- number LIKE ?
- OR name LIKE ?
+ lines.number LIKE ?
+ OR lines.name LIKE ?
+ OR companies.name ILIKE ?
SQL
@lines = @lines
+ .joins(:company)
.where(
filter,
- *Array.new(2, "#{params[:q]}%")
+ *Array.new(3, "%#{params[:q]}%")
)
.search(params[:q])
.result