Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Note
iconfalse

This type of entity class enable one-to-one model correspondence. For more complex needs, please refer to the complex entity section below.


Info
titleBusiness Rules

When mapping sensible data it is important to maintain consistency, and some applications might have a complex structure (.i.e allowing multi currency, different time-zones etc...). A guide to Business Rules can be found Here

FAQ

Expand
titleHow to handle references between entities?

Let's imagine you are mapping people to contacts, and the have a reference to the organization (or company) they belong to.

The first thing you need to do is to map the two reference fields:

Code Block
languageruby
class ContactMapper
  extend HashMapper
 
  map from('organization_id'), to('companyId')
end 


Once that is done, the second and only thing you need to do is to declare that this field is a reference, so that the framework know it has something specific to do with it. That's done in a method in your entity class:

Code Block
languageruby
class Contact < Maestrano::Connector::Rails::Entity
  def self.references
    %w(organization_id)
  end
end


You can define as many references as you need. Note that you should always declare references using the Connec!™ name of the field.



Status
colourGreen
titleTEST
If all go well, you should see in your specs when mapping from external to Connec!™ that the organization_id field is an array of hashes with a provider, a realm and an id.



If the entity you are mapping has nested sub-fields (e.g. an invoice can have an array of lines, a customer can have an array of notes, a warehouse can have an array of items etc...) you would need to declare them as well:

Code Block
languageruby
def self.references
  {
    record_references: %w(organization_id lines/item_id lines/tax_code_id lines/account_id)
    id_references: %w(lines/id)
  }
end

id_references does not prevent the entity to be pushed.

...

Also don't forget that each entity your connector synchronize should be declared in the External class, and, because the synchronizable entities are stored in the local database for each organization, you'll need to create a migration for existing organization if you add an new entity after the release. (And only after the release. In development, just add the new entity to your organization synchronized_entities list with a rails console).

Business Rules FAQ

Expand
titleI would like to not send updates of the prices field after checking that the currency does not match

In each entity model, you can set metadata on each specific entity IdMap and specify which fields you do not want to be updated:

Code Block
languageruby
# Inside the model
  def self.currency_check_fields
    %w(sale_price purchase_price)
  end

# Inside the mapper after_normalize hook
  unless keep_price # will be true if you wanted to keep the price 
    output.delete(:the_price_field)
    idmap = input['idmap']
    idmap.update_attributes(metadata: idmap.metadata.merge(ignore_currency_update: true)) if idmap
  end

The specified fields will now be ignored in subsequent updates from your application.

Triggering synchronizations

...