jaystack / jaydata

Notice: this library isn't maintained anymore
http://jaydata.org
GNU General Public License v2.0
352 stars 94 forks source link

Odata and inherited types - multiple levels of inheritance, data not populated. JayData 1.5.6 (release) #274

Open radicalapps opened 8 years ago

radicalapps commented 8 years ago

I have a data model in which there are is more than one level of inheritance. Jaydata 1.5.6 does not populate the data entities correctly.

Scenario: Make a simple query (toArray) to retrieve Groups from my OData Context. The OData query runs as expected, and I can use Fiddler to see that the data is returned from the service as expected. However, JayData is only populating the data fields in the most-derived level of the class hierarchy.

Observed behaviour: In an inheritance hierarchy MostDerived->Derived->Base->$data.Entity, only the data fields of the class "MostDerived" are populated. The fields that belong to "Derived" and "Base" are undefined.

Expected behaviour: In an inheritance hierarchy MostDerived->Derived->Base->$data.Entity, the data fields at all levels of the class hierarchy should be populated with data values.

My class hierarchy is below.

types["MyApp.Models.Group"] = $data("$data.Entity").extend("MyApp.Models.Group", {
    Id: {
        "type": "Edm.Int32",
        "nullable": false,
        "required": true,
        "key": true
    },
    Guid: {
        "type": "Edm.Guid"
    },
    Name: {
        "type": "Edm.String"
    },
    Roles: {
        "type": "Array",
        "elementType": "MyApp.Models.GroupRole",
        "inverseProperty": "$$unbound"
    },
    Assignments: {
        "type": "Array",
        "elementType": "MyApp.Models.GroupAssignment",
        "inverseProperty": "$$unbound"
    }
});

types["MyApp.Models.ParentGroup"] = types["MyApp.Models.Group"].extend("MyApp.Models.ParentGroup", {
    Groups: {
        "type": "Array",
        "elementType": "MyApp.Models.MemberGroup",
        "inverseProperty": "$$unbound"
    }
});

types["MyApp.Models.EstablishmentGroup"] = types["MyApp.Models.ParentGroup"].extend("MyApp.Models.EstablishmentGroup", {
    EstablishmentGuid: {
        "type": "Edm.Guid"
    },
    EstablishmentId: {
        "type": "Edm.Int32"
    },
    Parent: {
        "type": "MyApp.Models.Establishment",
        "inverseProperty": "$$unbound"
    }
});

types["MyApp.Models.MemberGroup"] = types["MyApp.Models.ParentGroup"].extend("MyApp.Models.MemberGroup", {
    ParentGroupId: {
        "type": "Edm.Int32"
    },
    Parent: {
        "type": "MyApp.Models.ParentGroup",
        "inverseProperty": "$$unbound"
    }
});