fix: column name ambiguous error in array operator (#4401)

* fix: column name ambiguous error in array operator

* fix: test
This commit is contained in:
ChengLei Shao 2024-05-19 18:33:40 +08:00 committed by GitHub
parent 8b3b9b3b26
commit c3a106bcd7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 35 additions and 1 deletions

View File

@ -204,6 +204,37 @@ describe('array field operator', function () {
expect(filter3[0].get('name')).toEqual(t2.get('name'));
});
test('$anyOf with association with same column name', async () => {
const Tag = db.collection({
name: 'tags',
fields: [
{ type: 'array', name: 'type' },
{ type: 'string', name: 'name' },
],
});
const Post = db.collection({
name: 'posts',
tableName: 'posts_table',
fields: [
{ type: 'array', name: 'type' },
{
type: 'hasMany',
name: 'tags',
},
],
});
await db.sync({ force: true });
await Post.repository.find({
filter: {
'type.$anyOf': ['aa'],
'tags.name': 't1',
},
});
});
// fix https://nocobase.height.app/T-2803
test('$anyOf with string', async () => {
const filter3 = await Test.repository.find({

View File

@ -33,15 +33,18 @@ const getFieldName = (ctx) => {
const model = getModelFromAssociationPath();
let columnPrefix = model.name;
if (model.rawAttributes[fieldName]) {
columnName = model.rawAttributes[fieldName].field || fieldName;
}
if (associationPath.length > 0) {
const association = associationPath.join('->');
columnName = `${association}.${columnName}`;
columnPrefix = association;
}
columnName = `${columnPrefix}.${columnName}`;
return columnName;
};