Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set multiplicity attribute #22

Open
kbarbounakis opened this issue Nov 16, 2020 · 0 comments
Open

Set multiplicity attribute #22

kbarbounakis opened this issue Nov 16, 2020 · 0 comments

Comments

@kbarbounakis
Copy link
Contributor

Description
Any data field that defines a data association between two models has multiplicity property which is readonly and defines the multiplicity level of an association. DataField.multiplicity can be one of "Many", "One", "ZeroOrOne". Its value is always calculated while getting a data model and cannot be set through data model definition.

Sometimes a one-to-many association between two models may be a one-to-one association e.g.

Parent model has two properties which associate parent model with child model. The first activeChild is a readonly association with filter which returns always an array with zero or one items. The second one children returns an array of associated items.

{
    "name": "ParentModel",
    "fields": [
       ...,
           {
           "name": "activeChild",
           "type": "ChildModel",
           "many": true,
           "readonly": true,
           "cascade": "delete"
           "mapping": {
                 "type": "association",
                 "parentModel": "ParentModel",
                 "parentField": "id",
                 "childModel": "ChildModel",
                 "childField": "object",
                 "options": {
                      "$filter": "active eq true"
                  }
             }
          },
          {
           "name": "children",
           "type": "ChildModel",
           "many": true,
           "cascade": "delete"
           "mapping": {
                 "type": "association",
                 "parentModel": "ParentModel",
                 "parentField": "id",
                 "childModel": "ChildModel",
                 "childField": "object"
             }
          }
      ]
   }
}

So activeChild property has "ZeroOrOne" multiplicity but the calculated multiplicity attribute is 'Many'.

{
         activeChild: {
             ...
         },
         children: [
             ...
        ]
}

Child model:

{
    "name": "ChildModel",
    "fields": [
       ...,
           {
           "name": "object",
           "type": "ParentModel"
           },
           {
           "name": "active",
           "type": "Boolean"
           }
      ]
   }
}

Solution
Let DataField.multiplicity to be editable in order to have an option to set it as 'Many' or 'ZeroOrOne'. Of course this operation needs extra validation to avoid errors for wrong values of multiplicity property.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant