Class: ForestAdminDatasourceMambuPayments::Plugins::Relations::LinkPaymentOrderToTransactions
- Inherits:
-
ForestAdminDatasourceCustomizer::Plugins::Plugin
- Object
- ForestAdminDatasourceCustomizer::Plugins::Plugin
- ForestAdminDatasourceMambuPayments::Plugins::Relations::LinkPaymentOrderToTransactions
- Defined in:
- lib/forest_admin_datasource_mambu_payments/plugins/relations/link_payment_order_to_transactions.rb
Overview
Exposes a navigable PaymentOrder <-> Transaction link. Transaction has no native payment_order_id; the relation is mediated by MambuReconciliation (Reconciliation.payment_id + payment_type discriminator). See TwoStepReconciliationFilter for the OneToMany filter rewrite.
Install at the datasource level:
@agent.use(
ForestAdminDatasourceMambuPayments::Plugins::Relations::LinkPaymentOrderToTransactions,
{}
)
Constant Summary collapse
- ComputedDefinition =
ForestAdminDatasourceCustomizer::Decorators::Computed::ComputedDefinition
- PAYMENT_ORDER =
'MambuPaymentOrder'.freeze
- TRANSACTION =
'MambuTransaction'.freeze
- FK_NAME =
'payment_order_id'.freeze
- PAYMENT_TYPE =
'payment_order'.freeze
- ONE_TO_MANY_NAME =
'transactions'.freeze
Instance Method Summary collapse
Instance Method Details
#run(datasource_customizer, _collection_customizer = nil, _options = {}) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/forest_admin_datasource_mambu_payments/plugins/relations/link_payment_order_to_transactions.rb', line 23 def run(datasource_customizer, _collection_customizer = nil, = {}) Plugins::Helpers.require_datasource!(datasource_customizer, self.class) datasource_customizer.customize_collection(TRANSACTION) do |c| # Virtual column: Transaction has no native payment_order_id. # Reverse lookup would require scanning all reconciliations — kept # nil per record; only EQUAL/IN filters are rewritten via the # TwoStepReconciliationFilter below. c.add_field(FK_NAME, ComputedDefinition.new( column_type: 'String', dependencies: ['id'], values: proc { |records, _ctx| records.map { nil } } )) TwoStepReconciliationFilter.install(c, fk_name: FK_NAME, payment_type: PAYMENT_TYPE, target_field: 'id') end datasource_customizer.customize_collection(PAYMENT_ORDER) do |c| c.add_one_to_many_relation(ONE_TO_MANY_NAME, TRANSACTION, origin_key: FK_NAME, origin_key_target: 'id') end end |