Skip to content

Commit

Permalink
[api] flags: Refactor before validation task
Browse files Browse the repository at this point in the history
- Use main_object helper to remove condition
- Use .to_i to avoid specific nil handling
  • Loading branch information
bgeuken committed Nov 13, 2016
1 parent 075c39f commit 0e4b201
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions src/api/app/models/flag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ class Flag < ApplicationRecord
after_destroy :discard_forbidden_project_cache

before_validation(on: :create) do
if project
self.position = (project.flags.maximum(:position) || 0 ) + 1
elsif package
self.position = (package.flags.maximum(:position) || 0 ) + 1
end
self.position = main_object.flags.maximum(:position).to_i + 1
end

validate :validate_custom_save
Expand Down

0 comments on commit 0e4b201

Please sign in to comment.