Commit ce1b79afa9faa8ffaae7392f9e48273c230753c4
1 parent
8b76e306
Exists in
master
and in
4 other branches
SQL Fixes
Showing
3 changed files
with
9 additions
and
5 deletions
Show diff stats
app/controllers/groups_controller.rb
app/models/group.rb
| ... | ... | @@ -23,10 +23,14 @@ class Group < ActiveRecord::Base |
| 23 | 23 | delegate :name, to: :owner, allow_nil: true, prefix: true |
| 24 | 24 | |
| 25 | 25 | def self.search query |
| 26 | - where("name like :query or code like :query", query: "%#{query}%") | |
| 26 | + where("name like :query OR code like :query", query: "%#{query}%") | |
| 27 | 27 | end |
| 28 | 28 | |
| 29 | 29 | def to_param |
| 30 | 30 | code |
| 31 | 31 | end |
| 32 | + | |
| 33 | + def users | |
| 34 | + User.joins(:users_projects).where('users_projects.project_id' => project_ids).uniq | |
| 35 | + end | |
| 32 | 36 | end | ... | ... |
app/models/project.rb
| ... | ... | @@ -30,15 +30,15 @@ class Project < ActiveRecord::Base |
| 30 | 30 | |
| 31 | 31 | # Scopes |
| 32 | 32 | scope :public_only, where(private_flag: false) |
| 33 | - scope :without_user, ->(user) { where("id not in (:ids)", ids: user.projects.map(&:id) ) } | |
| 34 | - scope :not_in_group, ->(group) { where("id not in (:ids)", ids: group.project_ids ) } | |
| 33 | + scope :without_user, ->(user) { where("id NOT IN (:ids)", ids: user.projects.map(&:id) ) } | |
| 34 | + scope :not_in_group, ->(group) { where("id NOT IN (:ids)", ids: group.project_ids ) } | |
| 35 | 35 | |
| 36 | 36 | def self.active |
| 37 | 37 | joins(:issues, :notes, :merge_requests).order("issues.created_at, notes.created_at, merge_requests.created_at DESC") |
| 38 | 38 | end |
| 39 | 39 | |
| 40 | 40 | def self.search query |
| 41 | - where("name like :query or code like :query or path like :query", query: "%#{query}%") | |
| 41 | + where("name like :query OR code like :query OR path like :query", query: "%#{query}%") | |
| 42 | 42 | end |
| 43 | 43 | |
| 44 | 44 | def self.create_by_user(params, user) | ... | ... |