Nullify deliveries and orders depending on an invoice (#718)

This commit is contained in:
Patrick Gansterer 2020-06-22 17:03:58 +02:00
parent 5eb8abf431
commit fc22a97f52
2 changed files with 10 additions and 2 deletions

View File

@ -4,8 +4,8 @@ class Invoice < ApplicationRecord
belongs_to :supplier
belongs_to :created_by, :class_name => 'User', :foreign_key => 'created_by_user_id'
belongs_to :financial_link
has_many :deliveries
has_many :orders
has_many :deliveries, dependent: :nullify
has_many :orders, dependent: :nullify
validates_presence_of :supplier_id
validates_numericality_of :amount, :deposit, :deposit_credit

View File

@ -0,0 +1,8 @@
class ClearInvalidInvoicesFromOrders < ActiveRecord::Migration
class Order < ActiveRecord::Base; end
class Invoice < ActiveRecord::Base; end
def up
Order.where.not(invoice_id: Invoice.all).update_all(invoice_id: nil)
end
end