atviriduomenys / spinta

Spinta is a framework to describe, extract and publish data (a DEP Framework).
MIT License
10 stars 4 forks source link

Nested backrefs and arrays #651

Open sirex opened 2 weeks ago

sirex commented 2 weeks ago

When a property is a part of an array or backref, then property.source must be relative to property.source of array property.

For example, if we have following XML data:

<root>
    <object id="1">
        <fact id="1">
            <doc id="1" />
            <doc id="2" />
        </fact>
        <fact id="2">
            <doc id="3" />
            <doc id="4" />
        </fact>
    </object>
</root>

The manifest table should be:

model   property            type        ref         source
Object                                  id          root/object
        id                  integer                 @id
        facts[]             backref     Fact        fact
        facts[].id          backref                 @id   
        facts[].docs[]      backref     Document    doc
        facts[].docs[].id   backref                 @id
Fact                                    id          root/object/fact
        id                  integer                 @id
        object              ref         Object      ../@id
Document                                id          root/object/fact/doc
        id                  integer                 @id
        fact                ref         Fact        ../@id

Object/facts[].id property has @id in source, which is relative to source of Object/facts[].

Similar, but not exactly the same situation with tabular data, for example if we have following table:

object  fact  doc       
1       1     1
1       1     2
1       2     3
1       2     4

Then, manifest table would be:

model   property            type        ref         source
Object                                  id          table
        id                  integer                 object
        facts[]             backref     Fact        fact
        facts[].id          backref                 fact
        facts[].docs[]      backref     Document    doc
        facts[].docs[].id   backref                 doc
Fact                                    id          table
        id                  integer                 fact
        object              ref         Object      object
Document                                id          table
        id                  integer                 doc
        fact                ref         Fact        fact

In both cases (XML and tabular), UAPI JSON result for Object should be:

{
    "_type": "Object",
    "id": 1,
    "facts": [
        {
            "_type": "Fact",
            "id": 1,
            "docs": [
                {
                    "_type": "Document",
                    "id": 1,
                },
                {
                    "_type": "Document",
                    "id": 2,
                },
            ]
        },
        {
            "_type": "Fact",
            "id": 2,
            "docs": [
                {
                    "_type": "Document",
                    "id": 3,
                },
                {
                    "_type": "Document",
                    "id": 4,
                },
            ]
        }
    ],
}

Resources