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({
|
||||
transaction,
|
||||
});
|
||||
|
||||
const emptyCount = await this.collection.repository.count({
|
||||
filter: {
|
||||
[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,
|
||||
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,
|
||||
});
|
||||
|
||||
// @ts-ignore
|
||||
return count;
|
||||
}
|
||||
|
||||
|
@ -75,6 +75,18 @@ describe('collections repository', () => {
|
||||
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 () => {
|
||||
const response1 = await app.agent().resource('posts').create();
|
||||
const postId = response1.body.data.id;
|
||||
|
Loading…
Reference in New Issue
Block a user