2024-02-23 21:34:33 -05:00
|
|
|
class Transaction < ApplicationRecord
|
|
|
|
belongs_to :account
|
2024-03-07 19:15:50 +01:00
|
|
|
belongs_to :category, optional: true
|
2024-02-29 08:32:52 -05:00
|
|
|
|
2024-03-15 12:21:59 -07:00
|
|
|
validates :name, :date, :amount, :account, presence: true
|
|
|
|
|
2024-02-29 08:32:52 -05:00
|
|
|
after_commit :sync_account
|
|
|
|
|
2024-03-11 14:51:16 +02:00
|
|
|
def self.ransackable_attributes(auth_object = nil)
|
|
|
|
%w[name amount date]
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.ransackable_associations(auth_object = nil)
|
|
|
|
%w[category account]
|
|
|
|
end
|
|
|
|
|
2024-02-29 08:32:52 -05:00
|
|
|
private
|
|
|
|
|
|
|
|
def sync_account
|
|
|
|
self.account.sync_later
|
|
|
|
end
|
2024-02-23 21:34:33 -05:00
|
|
|
end
|