Skip to content
This repository has been archived by the owner on Apr 11, 2023. It is now read-only.

Commit

Permalink
Fix inheritance associations
Browse files Browse the repository at this point in the history
  • Loading branch information
lazarv committed Sep 27, 2016
1 parent 08d5ff9 commit b9cfe82
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 5 deletions.
2 changes: 1 addition & 1 deletion dist/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jaydata",
"version": "1.5.8",
"version": "1.5.9",
"description": "Cross-platform HTML5 data-management, JavaScript Language Query (JSLQ) support for OData, SQLite, WebSQL, IndexedDB, YQL and Facebook (packaged for Node.JS)",
"keywords": [
"HTML5 data management",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jaydata",
"version": "1.5.8",
"version": "1.5.9",
"description": "Cross-platform HTML5 data-management, JavaScript Language Query (JSLQ) support for OData, SQLite, WebSQL, IndexedDB, YQL and Facebook (packaged for Node.JS)",
"keywords": [
"HTML5 data management",
Expand Down
4 changes: 2 additions & 2 deletions src/Types/EntityContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ $data.Class.define('$data.EntityContext', null, null,

this._addNavigationPropertyDefinition(dbEntityInstanceDefinition, memDef, memDef.name);
var associationType = memDef.inverseProperty === '$$unbound' ? '$$unbound' : '0..1';
var association = this._addAssociationElement(storageModel.LogicalType, associationType, memDef.name, refereedStorageModel.LogicalType, "*", memDef.inverseProperty);
var association = this._addAssociationElement(memDef.definedBy, associationType, memDef.name, refereedStorageModel.LogicalType, "*", memDef.inverseProperty);
storageModel.Associations[memDef.name] = association;
storageModel.Associations.push(association);
},
Expand Down Expand Up @@ -656,7 +656,7 @@ $data.Class.define('$data.EntityContext', null, null,

this._addNavigationPropertyDefinition(dbEntityInstanceDefinition, memDef, memDef.name);

var association = this._addAssociationElement(storageModel.LogicalType,
var association = this._addAssociationElement(memDef.definedBy,
memDef.required ? "0..1" : "1",
memDef.name,
refereedStorageModel.LogicalType,
Expand Down
35 changes: 34 additions & 1 deletion test/unit-tests/ODataV4ReadTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ describe('OData protocol tests', function () {
})
})

describe.only('inheritance', () => {
describe('inheritance', () => {
it('read', () => {
return ctx.GenericArticles.toArray().then((articles) => {
expect(articles.filter(it => it.Id == 1)[0].getType()).to.equal($data('Inheritance.PublicArticle'));
Expand Down Expand Up @@ -567,6 +567,39 @@ describe('OData protocol tests', function () {
ctx.prepareRequest = t;
return p;
});

it('include 1..*', () => {
var q = ctx.GenericArticles.include('RelatedAuthors').toTraceString();
expect(q.queryText).to.equal('/GenericArticles?$expand=Inheritance.PublicArticle/RelatedAuthors');
});

it('include 1..1', () => {
$data.Entity.extend('myBaseClass', {
id: { type: 'int', computed: true, key: true }
});

$data('myBaseClass').extend('myInheritedClass', {
association: { type: 'anotherInheritedClass', inverseProperty: 'inverse', required: true }
});

$data.Entity.extend('anotherClass', {
foobar: { type: 'string' }
});

$data.Entity.extend('anotherInheritedClass', {
inverse: { type: 'myInheritedClass', inverseProperty: 'association' }
});

$data.EntityContext.extend('myInheritanceContext', {
mySet: { type: $data.EntitySet, elementType: 'myBaseClass' }
});

var ctx = new ($data('myInheritanceContext'))('http://myodataservice.com');
return ctx.onReady().then(() => {
var q = ctx.mySet.include('association').toTraceString();
expect(q.queryText).to.equal('/mySet?$expand=myInheritedClass/association');
});
});
});

})
Expand Down

0 comments on commit b9cfe82

Please sign in to comment.