mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-05 13:39:24 +08:00
fix: count of multi filter target keys (#5251)
This commit is contained in:
parent
51417a24de
commit
da4a5b56e5
@ -21,6 +21,60 @@ describe('multi filter target key', () => {
|
|||||||
await db.close();
|
await db.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should get count of multi filter target keys', async () => {
|
||||||
|
const Student = db.collection({
|
||||||
|
name: 'students',
|
||||||
|
autoGenId: false,
|
||||||
|
filterTargetKey: ['name', 'classId'],
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
name: 'name',
|
||||||
|
type: 'string',
|
||||||
|
primaryKey: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'classId',
|
||||||
|
type: 'bigInt',
|
||||||
|
primaryKey: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'age',
|
||||||
|
type: 'integer',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
await db.sync();
|
||||||
|
|
||||||
|
const s1 = await Student.repository.create({
|
||||||
|
values: {
|
||||||
|
name: 's1',
|
||||||
|
classId: 1,
|
||||||
|
age: 10,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const s2 = await Student.repository.create({
|
||||||
|
values: {
|
||||||
|
name: 's1',
|
||||||
|
classId: 2,
|
||||||
|
age: 10,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const s3 = await Student.repository.create({
|
||||||
|
values: {
|
||||||
|
name: 's3',
|
||||||
|
classId: 2,
|
||||||
|
age: 10,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const count = await Student.repository.count({});
|
||||||
|
|
||||||
|
expect(count).toBe(3);
|
||||||
|
});
|
||||||
|
|
||||||
it('should set multi filter target keys', async () => {
|
it('should set multi filter target keys', async () => {
|
||||||
const Student = db.collection({
|
const Student = db.collection({
|
||||||
name: 'students',
|
name: 'students',
|
||||||
|
@ -187,6 +187,10 @@ export class Collection<
|
|||||||
return this.model.primaryKeyAttribute;
|
return this.model.primaryKeyAttribute;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isMultiFilterTargetKey() {
|
||||||
|
return Array.isArray(this.filterTargetKey) && this.filterTargetKey.length > 1;
|
||||||
|
}
|
||||||
|
|
||||||
get name() {
|
get name() {
|
||||||
return this.options.name;
|
return this.options.name;
|
||||||
}
|
}
|
||||||
|
@ -326,7 +326,7 @@ export class Repository<TModelAttributes extends {} = any, TCreationAttributes e
|
|||||||
|
|
||||||
const queryOptions: any = {
|
const queryOptions: any = {
|
||||||
...options,
|
...options,
|
||||||
distinct: Boolean(this.collection.model.primaryKeyAttribute),
|
distinct: Boolean(this.collection.model.primaryKeyAttribute) && !this.collection.isMultiFilterTargetKey(),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (queryOptions.include?.length === 0) {
|
if (queryOptions.include?.length === 0) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user