Simplify a builder expansion in SupporterNote
This commit is contained in:
parent
8bd3837b54
commit
fb03b49806
1 changed files with 2 additions and 4 deletions
|
@ -10,6 +10,7 @@ class SupporterNote < ApplicationRecord
|
|||
# :supporter_id, :supporter
|
||||
|
||||
belongs_to :supporter
|
||||
has_one :nonprofit, through: :supporter
|
||||
has_many :activities, as: :attachment, dependent: :destroy
|
||||
belongs_to :user
|
||||
|
||||
|
@ -17,14 +18,11 @@ class SupporterNote < ApplicationRecord
|
|||
validates :supporter_id, presence: true
|
||||
# TODO replace with Discard gem
|
||||
|
||||
add_builder_expansion :supporter
|
||||
add_builder_expansion :supporter, :nonprofit
|
||||
add_builder_expansion :user,
|
||||
to_id: ->(model) { model.user&.id},
|
||||
to_expand: ->(model) { model.user&.to_builder}
|
||||
|
||||
add_builder_expansion :nonprofit,
|
||||
to_attrib: -> (model) {model.supporter.nonprofit}
|
||||
|
||||
define_model_callbacks :discard
|
||||
|
||||
after_discard :publish_deleted
|
||||
|
|
Loading…
Reference in a new issue