Class: Move
Class Method Summary collapse
-
.find_conflict(item) ⇒ Object
validations.
Instance Method Summary collapse
Methods inherited from Item
Class Method Details
.find_conflict(item) ⇒ Object
validations
9 10 11 12 13 14 15 16 |
# File 'app/models/move.rb', line 9 def self.find_conflict(item) Move.all(:conditions => { :date => item.date, :account_id_from => item.account_id_from, :account_id_to => item.account_id_to, :position => item.position, }).reject{|x| x.id == item.id}.first end |
Instance Method Details
#find_position ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/models/move.rb', line 33 def find_position klass = self.class items = klass.all(conditions: { date: self.date, account_id_from: self.account_id_from, account_id_to: self.account_id_to, }) n = 0 loop do if items.none?{|item| item.position == n} $stderr.puts "[find_position] #{n}" return n end n += 1 end end |
#validate ⇒ Object
18 19 20 21 22 23 |
# File 'app/models/move.rb', line 18 def validate if account_id_from && (account_id_from == account_id_to) errors.add("account_id_from", "from and to must not be same") end super end |