mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-24 03:00:12 +01:00
Prefer find_by over detect
Uses a better SQL query to pull a single object vs. pulling a full set and then iterating over it.
This commit is contained in:
parent
ec59f10af8
commit
596096b8d5
1 changed files with 1 additions and 1 deletions
|
|
@ -28,7 +28,7 @@ class User < ApplicationRecord
|
|||
end
|
||||
def update_positions(project_ids)
|
||||
project_ids.each_with_index {|id, position|
|
||||
project = self.detect { |p| p.id == id.to_i }
|
||||
project = self.find_by(id: id.to_i)
|
||||
raise I18n.t('models.user.error_project_not_associated', :project => id, :user => @user.id) if project.nil?
|
||||
project.update_attribute(:position, position + 1)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue