Class: ForestAdminDatasourceMambuPayments::Plugins::Relations::OneToManyLinkPlugin

Inherits:
ForestAdminDatasourceCustomizer::Plugins::Plugin
  • Object
show all
Defined in:
lib/forest_admin_datasource_mambu_payments/plugins/relations/one_to_many_link_plugin.rb

Overview

Base for the “simple” reciprocal OneToMany links: the target already carries a native foreign key, so the plugin only declares the relation on the host. Subclasses configure it declaratively:

class LinkExternalAccountToIncomingPayments < OneToManyLinkPlugin
  link host: 'MambuExternalAccount', to: 'MambuIncomingPayment',
       name: 'incoming_payments', origin_key: 'external_account_id'
end

Install at the datasource level: @agent.use(plugin, {}).

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.configObject (readonly)

Returns the value of attribute config.



16
17
18
# File 'lib/forest_admin_datasource_mambu_payments/plugins/relations/one_to_many_link_plugin.rb', line 16

def config
  @config
end

Class Method Details



19
20
21
# File 'lib/forest_admin_datasource_mambu_payments/plugins/relations/one_to_many_link_plugin.rb', line 19

def self.link(host:, to:, name:, origin_key:)
  @config = { host: host, to: to, name: name, origin_key: origin_key }
end

Instance Method Details

#run(datasource_customizer, _collection_customizer = nil, _options = {}) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/forest_admin_datasource_mambu_payments/plugins/relations/one_to_many_link_plugin.rb', line 23

def run(datasource_customizer, _collection_customizer = nil, _options = {})
  Plugins::Helpers.require_datasource!(datasource_customizer, self.class)

  cfg = self.class.config
  datasource_customizer.customize_collection(cfg[:host]) do |c|
    c.add_one_to_many_relation(cfg[:name], cfg[:to],
                               origin_key: cfg[:origin_key], origin_key_target: 'id')
  end
end