Skip to content

Commit

Permalink
Related to #10
Browse files Browse the repository at this point in the history
  • Loading branch information
BlairAllegroTech committed Jul 28, 2016
1 parent b4aa45f commit 87fc330
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 92 deletions.
5 changes: 4 additions & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,17 @@ module.exports = function (config) {

// list of files / patterns to load in the browser
files: [
// simple pattern to load the needed testfiles
// equal to {pattern: 'test/unit/*.spec.js', watched: true, served: true, included: true}

'node_modules/es6-promise/dist/es6-promise.js',
'node_modules/axios/dist/axios.js',
'node_modules/js-data/dist/js-data.js',
'node_modules/js-data-http/dist/js-data-http.js',
'dist/js-data-jsonapi.js',

'karma.start.js',
'test/**/*.js',
'test/*.js',

'examples/**/*.js',

Expand Down
15 changes: 11 additions & 4 deletions src/JsonApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,20 @@ export class JsonApiRelationship {
}
}



WithData(type: string, id: string): JsonApiRelationship {
if (this.data && Array.isArray(this.data)) {
(<JsonApiData[]>this.data).push(new JsonApiData(type).WithId(id));

if (type && id) {
if (this.data && Array.isArray(this.data)) {
(<JsonApiData[]>this.data).push(new JsonApiData(type).WithId(id));
} else {
this.data = new JsonApiData(type).WithId(id);
}
return this;
} else {
this.data = new JsonApiData(type).WithId(id);
throw new Error('Invalid call to "JsonApiRelationship.WithData" type and id required');
}
return this;
}

AddLink(linkType: string, link: MetaLink): JsonApiRelationship {
Expand Down
1 change: 1 addition & 0 deletions src/JsonApiSerializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ export class SerializationOptions {
* @param localFieldName The local field name for the relationship, incase there is more than one relationship on the object of the given type
*/
getChildRelationWithLocalField(relationType: string, localFieldName: string): JSData.RelationDefinition {

relationType = relationType.toLowerCase();
localFieldName = localFieldName.toLowerCase();

Expand Down
Loading

0 comments on commit 87fc330

Please sign in to comment.