fix: sort field with table dose not have primary key (#1119)
This commit is contained in:
parent
fba8f253d4
commit
466aa4987e
@ -45,6 +45,7 @@ export class SortField extends Field {
|
|||||||
const totalCount = await this.collection.repository.count({
|
const totalCount = await this.collection.repository.count({
|
||||||
transaction,
|
transaction,
|
||||||
});
|
});
|
||||||
|
|
||||||
const emptyCount = await this.collection.repository.count({
|
const emptyCount = await this.collection.repository.count({
|
||||||
filter: {
|
filter: {
|
||||||
[this.name]: null,
|
[this.name]: null,
|
||||||
|
@ -210,12 +210,21 @@ export class Repository<TModelAttributes extends {} = any, TCreationAttributes e
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const count = await this.collection.model.count({
|
const queryOptions: any = {
|
||||||
...options,
|
...options,
|
||||||
distinct: true,
|
distinct: Boolean(this.collection.model.primaryKeyAttribute),
|
||||||
|
};
|
||||||
|
|
||||||
|
if (queryOptions.include?.length === 0) {
|
||||||
|
delete queryOptions.include;
|
||||||
|
}
|
||||||
|
|
||||||
|
const count = await this.collection.model.count({
|
||||||
|
...queryOptions,
|
||||||
transaction,
|
transaction,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,6 +75,18 @@ describe('collections repository', () => {
|
|||||||
await app.destroy();
|
await app.destroy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should create collection without id', async () => {
|
||||||
|
const response = await agent.resource('collections').create({
|
||||||
|
values: {
|
||||||
|
name: 'test',
|
||||||
|
autoGenId: false,
|
||||||
|
sortable: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(response.statusCode).toBe(200);
|
||||||
|
});
|
||||||
|
|
||||||
it('case 1', async () => {
|
it('case 1', async () => {
|
||||||
const response1 = await app.agent().resource('posts').create();
|
const response1 = await app.agent().resource('posts').create();
|
||||||
const postId = response1.body.data.id;
|
const postId = response1.body.data.id;
|
||||||
|
Loading…
Reference in New Issue
Block a user