From 186662b9ef2e996ec649298debb3df352f9849bf Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Wed, 7 Mar 2018 11:37:30 +0100 Subject: Chouette::Line#by_name: Use `LEFT OUTER JOIN` on "companies" Thanks to Johan for helping me with this. He correctly remarked that what I had before will do an `INNER JOIN`, which ends up excluding lines that don't have an associated company. I didn't really think about the data, and didn't realise we had lines without a company. Big thanks to Johan for seeing that I needed to add `public.` to qualify the `companies` table in order for the join to work. Otherwise it doesn't work correctly and we can't filter by company name. Refs #5889 --- app/models/chouette/line.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app') diff --git a/app/models/chouette/line.rb b/app/models/chouette/line.rb index f65d313b3..2f83fc5bf 100644 --- a/app/models/chouette/line.rb +++ b/app/models/chouette/line.rb @@ -44,7 +44,7 @@ module Chouette t: "%#{text.downcase}%") } scope :by_name, ->(name) { - joins(:company) + joins('LEFT OUTER JOIN public.companies ON companies.id = lines.company_id') .where(' lines.number LIKE :q OR lines.name LIKE :q -- cgit v1.2.3