Collection

Collection - is a data type that allows lists of other objects to be displayed in one object. The data of the object can be objects of any class including the initial.

References are separated by commas. All values from a sequence of references and commas are stored as a string in the database.

Ways to define collections:

in terms of the used fields of the attribute part of the class meta

  1. one-to-many is the classic relationship of a child object to a parent object. Indicates the presence of a container and a nested object with a reference to the container. In the container, you must specify the collection, and for the collection, specify the reference attribute of the nested object by which the link is formed. See Back References
  2. many-to-many is determined through a collection without references and a class of nested elements — connections are created in the collection and stored as separate entities in the DB. See Collections
  3. back collection is similar to the one-to-many connection but in the opposite direction - connection from the reference object. Set the connection using the backColl property. See Back collection

Collection attribute in JSON format

Example

{
      "orderNumber": 50,
      "name": "table",
      "caption": "Таблица",
      "type": 14,
      "size": null,
      "decimals": 0,
      "allowedFileTypes": null,
      "maxFileCount": 0,
      "nullable": true,
      "readonly": false,
      "indexed": false,
      "unique": false,
      "autoassigned": false,
      "hint": null,
      "defaultValue": null,
      "refClass": "",
      "itemsClass": "collRefCatalog@develop-and-test",
      "backRef": "",
      "backColl": "",
      "binding": "",
      "semantic": null,
      "selConditions": [],
      "selSorting": [],
      "selectionProvider": null,
      "indexSearch": false,
      "eagerLoading": false,
      "formula": null
 }

NB: If the collection refers to a class that contains many descendants, then when the collection is populated, it will be possible to create objects of both parent and child classes.

Collections together with the object are loaded according to the semantics specified in the meta class of a collection or reference attribute.

Back reference in the context of collections

The back reference in the context of collection is formed as follows:

  • create a regular collection specifying the reference attribute
  • The reference class must have a reference attribute that references the source class and has the unique property set to false. The attribute-reference value is assigned immediately when creating a link to the collection, without the need to save the form
  • specify the "backRef" property in the initial class of the collection. In this property, write down the code of the reference attribute from the reference class

Back reference attribute in JSON format

Example

{
      "orderNumber": 30,
      "name": "coll",
      "caption": "Коллекция с обратной ссылкой",
      "type": 14,
      "size": null,
      "decimals": 0,
      "allowedFileTypes": null,
      "maxFileCount": 0,
      "nullable": true,
      "readonly": false,
      "indexed": false,
      "unique": false,
      "autoassigned": false,
      "hint": null,
      "defaultValue": null,
      "refClass": null,
      "itemsClass": "ref_backcoll_ref@develop-and-test",
      "backRef": "ref_backcoll_ref",
      "backColl": "",
      "binding": "",
      "semantic": "backcoll_data",
      "selConditions": [],
      "selSorting": [],
      "selectionProvider": null,
      "indexSearch": false,
      "eagerLoading": true,
      "formula": null
 }

Display modes of the “Collection” type attribute on the form:

Display modes are set in the view meta. They can be defined using the "mode" property, or set by a template in the "options" property.

  • mode: 4 - “Tag Cloud” stores the values of one or several objects by reference in the form of tags, the name of which is determined by the semantics of the object by reference.
  • mode: 3 - “Table” stores the values of one or several objects by reference in a table, the columns of which are predefined for the view form.

Example

{
    "caption": "Таблица",
    "type": 3,
    "property": "table",
    "size": 2,
    "maskName": null,
    "mask": null,
    "mode": 3,
    "fields": [],
    "columns": [],
    ...
},
...
  • “Comment” - is set in the same way as the “Table” display mode, but with the template specified in the "options" property. It is a field that contains data that was predefined in the "columns" property for an object by reference. It is intended to discuss information on an object at a certain stage of a workflow.

Example

{
     "caption": "Коментарий",
     "type": 3,
     "property": "coment",
     "size": 2,
     "maskName": null,
     "mask": null,
     "mode": 3,
     "fields": [],
     "columns": [
       {
         "sorted": true,
         "caption": "Дата",
         "type": 120,
         "property": "date",
         ...
       },
       {
         "sorted": true,
         "caption": "Подтверждение (Обоснование)",
         "type": 7,
         "property": "descript",
         ...
       },
       {
         "caption": "Ведущий",
         "type": 2,
         "property": "owner",
         ...
       }
     ],
     "actions": null,
     "commands": [
       {
         "id": "CREATE",
         "caption": "Создать",
         "visibilityCondition": null,
         "enableCondition": null,
         "needSelectedItem": false,
         "signBefore": false,
         "signAfter": false,
         "isBulk": false
       },
       {
         "id": "EDIT",
         "caption": "Править",
         "visibilityCondition": null,
         "enableCondition": null,
         "needSelectedItem": true,
         "signBefore": false,
         "signAfter": false,
         "isBulk": false
       }
     ],
     "orderNumber": 80,
     ...
     "tags": null,
     "options": {
       "template": "comments",
       "comments": {
         "textProperty": "descript",
         "userProperty": "owner",
         "parentProperty": "answlink",
         "photoProperty": "owner_ref.foto.link",
         "dateProperty": "date"
       }
     }
}

Back collection

The example of the collection above is converted for the back reference as follows:

{
      "orderNumber": 30,
      "name": "backcoll",
      "caption": "Обратная коллекции",
      "type": 14,
      "size": null,
      "decimals": 0,
      "allowedFileTypes": null,
      "maxFileCount": 0,
      "nullable": true,
      "readonly": false,
      "indexed": false,
      "unique": false,
      "autoassigned": false,
      "hint": null,
      "defaultValue": null,
      "refClass": "",
      "itemsClass": "coll_backcoll_coll",
      "backRef": "",
      "backColl": "coll",
      "binding": "",
      "semantic": "backcoll_data",
      "selConditions": [],
      "selSorting": [],
      "selectionProvider": null,
      "indexSearch": false,
      "eagerLoading": true,
      "formula": null
 }

Pay attention to the indication of the additional value in the property "backColl"- the name of the attribute from the class in the collection (from the example it is coll)

Thus, a many-to-many relationship is implemented without an intermediate class. Not only can the "backcoll" attribute with the “Collection” type contain multiple references, but objects on references can also contain multiple references to objects of the source class in their “coll” collection.

Attention:

  • "type": 14 - the attribute type “Collection”
  • "backColl" - the name of the collection type reference attribute referencing the original collection class
  • "itemsClass" - the name of the class, the objects of which can store their identifiers in the collection and, thus, form a link to the object by identifier
  • "backRef" - reference-attribute from the reference class specified in "itemsClass"
  • When specifying a parent class, it is possible to create objects of the parent and child classes
  • Collections with objects are loaded according to the semantics specified in the collection class or the collection attribute

Collection processing scheme and DB storage format

To save the collection, transfer the array of actions (the example below) in the corresponding attribute of the object:

"collection": [
  {"action": "put", "id": "1234"},
  {"action": "put", "id": "1235"},
  {"action": "put", "id": "1236"},
  {"action": "eject", "id": "1230"}
]

The order of the objects must correspond to the order of relevant actions. Available operations: put - add to the collection, eject - extract from the collection. The algorithm for creating and editing is the same. Actions on collections are performed after the container is created or saved.

The working principle of collections on the form of creation and editing is fundamentally different:

  • On the creation form, interconnection with the server is required only to receive and display in the table the selected/created object of the collection
  • On the editing form, it is possible to get a server response if necessary, and to change the select parameters upon request, depending on the actions performed in the collection.