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

does not support sub paths #2

Open
AubreyHewes opened this issue Jun 25, 2020 · 2 comments · May be fixed by #12
Open

does not support sub paths #2

AubreyHewes opened this issue Jun 25, 2020 · 2 comments · May be fixed by #12

Comments

@AubreyHewes
Copy link
Member

When using with sub paths it fails;

i.e. one.two.three will always return the default value even if it is set:

$dataBag = DataBag::create();
$dataBag->addEntityData('one', ['two' => ['three' => 'value']]);
$dataBag->get('one.two.three'); // returns 'null' (the default) instead of the expected `value`

And also when setting it sets unexpected data:

$dataBag = DataBag::create();
$dataBag->set('one.two.three', 'value');
$state = $dataBag->getState(); // is not expected data

The above $state returns

{
  "one": {
    "two": [
      "value"
    ]
  }
}

Where two is not the expected object containing three with the value but an array just containing the value.

{
  "one": {
-    "two": {
-      "three": "value"
-    }
+    "two": [
+      "value"
+    ]
  }
}
@mishavantol
Copy link
Member

How would this be used/defined in CB? If it's aways an field pointing to an entity / array of entities it may not be the responsibility of the databag here. Maybe the object itself should use an sub-object/objectCollection instead. Like we do with address, phoneNumber and so.

@AubreyHewes
Copy link
Member Author

Examples:

Known File entity:
file.metadata.path <- ridiculous to add an extra FileMetaData php-entity just for this as path is the only field...
So just adding a File::getPath() returning the databag file.metadata.path should be possible.

Or may want to define a php-entity like this:

MyDebtorEntity::getStreet(); 
// returns for example debtor.addressReference.address.street via the DataBag solution 
// without having to define a load of misc php-entities

The main reason is that it is not a proper databag as you can not set/get more than two sub paths, and has unexpected behaviour due to this.

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