Project

General

Profile

Actions

Patch #40691

closed

Remove ambiguity in queries utilizing a Project scope

Added by Vincent Robert 2 months ago. Updated 2 months ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Code cleanup/refactoring
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:

Description

Hello
Please consider this patch which removes ambiguity in queries utilizing the scope "like" in the Project model.
It just adds the table name before the attribute.
Thank you

diff --git a/app/models/project.rb b/app/models/project.rb
index 9f9656976..9177a8b15 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -109,7 +109,7 @@ class Project < ActiveRecord::Base
   scope :like, (lambda do |arg|
     if arg.present?
       pattern = "%#{sanitize_sql_like arg.to_s.strip}%" 
-      where("LOWER(identifier) LIKE LOWER(:p) ESCAPE :s OR LOWER(name) LIKE LOWER(:p) ESCAPE :s", :p => pattern, :s => '\\')
+      where("LOWER(#{Project.table_name}.identifier) LIKE LOWER(:p) ESCAPE :s OR LOWER(#{Project.table_name}.name) LIKE LOWER(:p) ESCAPE :s", :p => pattern, :s => '\\')
     end
   end)
   scope :sorted, lambda {order(:lft)}


Files

patch.diff (667 Bytes) patch.diff Vincent Robert, 2024-05-13 18:07
Actions

Also available in: Atom PDF