Skip to content

Commit

Permalink
fix: serialized responses containing a self join is missing attributes (
Browse files Browse the repository at this point in the history
  • Loading branch information
zacharygolba authored Feb 15, 2017
1 parent 2e223df commit 7858af5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,39 +1,21 @@
// @flow
import type Controller from '../../../../controller';

import getDefaultMemberParams from './get-default-member-params';

/**
* @private
*/
export default function getDefaultCollectionParams({
model,
defaultPerPage,
serializer: {
hasOne,
hasMany,
attributes
}
}: Controller): Object {
function getDefaultCollectionParams(controller: Controller): Object {
return {
sort: 'createdAt',
...getDefaultMemberParams(controller),
filter: {},
fields: {
[model.resourceName]: attributes,
...[...hasOne, ...hasMany].reduce((include, key) => {
const opts = model.relationshipFor(key);

if (!opts) {
return include;
}

return {
...include,
[opts.model.resourceName]: [opts.model.primaryKey]
};
}, {})
},
sort: 'createdAt',
page: {
size: defaultPerPage,
size: controller.defaultPerPage,
number: 1
}
};
}

export default getDefaultCollectionParams;
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default function getDefaultMemberParams({
...[...hasOne, ...hasMany].reduce((include, key) => {
const opts = model.relationshipFor(key);

if (!opts) {
if (!opts || model === opts.model) {
return include;
}

Expand Down

0 comments on commit 7858af5

Please sign in to comment.