Skip to content

Commit 752953b

Browse files
committed
Merge pull request #32 from digitalsadhu/listepo/relation
Update
2 parents 781cadc + 519b27b commit 752953b

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

lib/errors.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ module.exports = function (app, options) {
3535
remotes.afterError('**', function (ctx, next) {
3636
var errors = [];
3737
var statusCode = 500;
38-
38+
debug('Errors:');
39+
debug(ctx.error);
3940
//validation errors
4041
if (ctx.error.details && ctx.error.details.messages) {
4142
errors = Object.keys(ctx.error.details.messages).map(function (key) {

lib/serializer.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ var parseResource = function (type, data, relations, options) {
2929
type = inflection.pluralize(type);
3030
type = caserize(type, options.keyForRelation);
3131
resource.type = type;
32-
var relationships = parseRelations(data, relations);
32+
var relationships = parseRelations(data, relations, options);
3333
if (!_.isEmpty(relationships)) {
3434
resource.relationships = relationships;
3535
}
@@ -75,9 +75,9 @@ var parseRelations = function (data, relations, options) {
7575
if (!_.isUndefined(value)) {
7676
delete data[fk];
7777
if (_.isArray(value)) {
78-
relationship = makeRelations(type, value);
78+
relationship = makeRelations(type, value, options);
7979
} else {
80-
relationship = makeRelation(type, value);
80+
relationship = makeRelation(type, value, options);
8181
}
8282
name = caserize(name, options.keyForRelation);
8383
relationships[name] = relationship;
@@ -86,7 +86,8 @@ var parseRelations = function (data, relations, options) {
8686
return relationships;
8787
};
8888

89-
var makeRelation = function (type, id) {
89+
var makeRelation = function (type, id, options) {
90+
type = caserize(type, options.keyForRelation);
9091
var data = {
9192
type: type,
9293
id: id
@@ -95,10 +96,10 @@ var makeRelation = function (type, id) {
9596
return {data: data};
9697
};
9798

98-
var makeRelations = function (type, ids) {
99+
var makeRelations = function (type, ids, options) {
99100
var res = [];
100101
_.each(ids, function (id) {
101-
res.push(makeRelation(type, id));
102+
res.push(makeRelation(type, id, options));
102103
});
103104
return res;
104105
};

test/belongsTo.test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ describe('loopback json api hasOne relationships', function () {
5555
expect(res.body).to.be.an('object');
5656
expect(res.body.links).to.be.an('object');
5757
expect(res.body.links.self).to.match(/comments\/1\/post/);
58-
console.log(res.body.data);
5958
expect(res.body.data).to.equal(null);
6059
done();
6160
});

test/update.test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ describe('loopback json api component update method', function () {
9898
})
9999
.set('Content-Type', 'application/json')
100100
.end(function (err, res) {
101-
console.log(res.body);
102101
expect(err).to.equal(null);
103102
expect(res.body).to.have.deep.property('data.links.self');
104103
expect(res.body.data.links.self).to.match(/http:\/\/127\.0\.0\.1.*\/posts\/1/);

0 commit comments

Comments
 (0)