Skip to content

Question about fieldPaths (feature request?) #1331

Open
@719media

Description

@719media

Clarification on fieldPaths, if a document with structure something like:

// 
{
  name: 'test',
  relationships: [
    { type: 'person', age: 32 },
    { type: 'asset', value: 15 }
  ],
}

was queried with a typeMap of

'typeMap' => [
  'root' => 'MyProject\MyClass',
  'array' => 'array',
  'document' => 'array',
  'fieldPaths' => [
    'relationships' => 'MyProject\MyRelationship'
  ],
],

That all works as expected. But, what if you wanted to use a different class depending on the type value? I understand if I had control of the schema, I could potentially use __pclass property... but in the scenario where the schema is fixed, could a different method be used? It doesn't seems like the fieldPaths option has any more verbose logic to use a field name to interpret the class... but perhaps there would be the ability to have the __pclass property able to be specified at query type? So something like

'typeMap' => [
  'root' => 'MyProject\MyClass',
  'array' => 'array',
  'document' => 'array',
  'fieldPaths' => [
    'relationships' => '$type' //this says to use the field "type" instead of "__pclass"
  ],
],

I suppose this example means that the field $type still has to be the fully qualified php class name, so I'm not sure it is really that helpful anyway...

Just wanted to know if you guys have come across this feature request?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions