Skip to content

Commit 7858af5

Browse files
authored
fix: serialized responses containing a self join is missing attributes (#675)
1 parent 2e223df commit 7858af5

File tree

2 files changed

+9
-27
lines changed

2 files changed

+9
-27
lines changed
Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,21 @@
11
// @flow
22
import type Controller from '../../../../controller';
33

4+
import getDefaultMemberParams from './get-default-member-params';
5+
46
/**
57
* @private
68
*/
7-
export default function getDefaultCollectionParams({
8-
model,
9-
defaultPerPage,
10-
serializer: {
11-
hasOne,
12-
hasMany,
13-
attributes
14-
}
15-
}: Controller): Object {
9+
function getDefaultCollectionParams(controller: Controller): Object {
1610
return {
17-
sort: 'createdAt',
11+
...getDefaultMemberParams(controller),
1812
filter: {},
19-
fields: {
20-
[model.resourceName]: attributes,
21-
...[...hasOne, ...hasMany].reduce((include, key) => {
22-
const opts = model.relationshipFor(key);
23-
24-
if (!opts) {
25-
return include;
26-
}
27-
28-
return {
29-
...include,
30-
[opts.model.resourceName]: [opts.model.primaryKey]
31-
};
32-
}, {})
33-
},
13+
sort: 'createdAt',
3414
page: {
35-
size: defaultPerPage,
15+
size: controller.defaultPerPage,
3616
number: 1
3717
}
3818
};
3919
}
20+
21+
export default getDefaultCollectionParams;

src/packages/router/route/params/utils/get-default-member-params.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default function getDefaultMemberParams({
1818
...[...hasOne, ...hasMany].reduce((include, key) => {
1919
const opts = model.relationshipFor(key);
2020

21-
if (!opts) {
21+
if (!opts || model === opts.model) {
2222
return include;
2323
}
2424

0 commit comments

Comments
 (0)