DataAssociationMapping

most-data/types~ DataAssociationMapping

DataAssociationMapping class describes the association between two models.

An association between two models is described in field attributes. For example model Order may have an association with model Party (Person or Organization) through the field Order.customer:


   { "name": "Order",
     "fields": [
    ...
   {
        "name": "customer",
        "title": "Customer",
        "description": "Party placing the order.",
        "type": "Party"
    }
    ...]
    }
 

This association is equivalent with the following DataAssociationMapping instance:


 "mapping": {
    "cascade": "null",
    "associationType": "association",
    "select": [],
    "childField": "customer",
    "childModel": "Order",
    "parentField": "id",
    "parentModel": "Party"
}
 

The above association mapping was auto-generated from the field definition of Order.customer where the field type (Party) actually defines the association between these models.

Another example of an association between two models is a many-to-many association. User model has a many-to-many association (for user groups) with Group model:


 { "name": "User",
   "fields": [
  ...
 {
    "name": "groups",
    "title": "User Groups",
    "description": "A collection of groups where user belongs.",
    "type": "Group",
    "expandable": true,
    "mapping": {
        "associationAdapter": "GroupMembers",
        "parentModel": "Group",
        "parentField": "id",
        "childModel": "User",
        "childField": "id",
        "associationType": "junction",
        "cascade": "delete"
    }
}
  ...]
  }
 

This association may also be defined in Group model:


 { "name": "Group",
   "fields": [
  ...
 {
    "name": "members",
    "title": "Group Members",
    "description": "Contains the collection of group members (users or groups).",
    "type": "Account",
    "many":true
}
  ...]
  }
 

Constructor

new DataAssociationMapping(objopt)

Parameters:
Name Type Attributes Description
obj * <optional>
An object that contains relation mapping attributes
Properties:
Name Type Description
associationAdapter string Gets or sets the association database object
parentModel string Gets or sets the parent model name
childModel string Gets or sets the child model name
parentField string Gets or sets the parent field name
childField string Gets or sets the child field name
refersTo string Gets or sets the parent property where this association refers to
parentLabel string Gets or sets the parent field that is going to be used as label for this association
cascade string Gets or sets the action that occurs when parent item is going to be deleted (all|none|null|delete). The default value is 'none'.
associationType string Gets or sets the type of this association (junction|association). The default value is 'association'.
select Array.<string> Gets or sets an array of fields to select from associated model. If this property is empty then all associated model fields will be selected.
Source: