fix: infer view field attribute (#5729)

* fix: view collection with field attribute

* fix: infer view with column field attribute
This commit is contained in:
ChengLei Shao 2024-11-26 16:39:21 +08:00 committed by GitHub
parent c7e4b63920
commit de7c86a1e5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 5 additions and 4 deletions

View File

@ -128,6 +128,7 @@ describe('view inference', function () {
const createdAt = UserCollection.model.rawAttributes['createdAt'].field;
expect(inferredFields[createdAt]['type']).toBe('date');
expect(inferredFields[createdAt]['field']).toBeDefined();
if (db.options.dialect == 'sqlite') {
expect(inferredFields['name']).toMatchObject({

View File

@ -52,7 +52,7 @@ export class ViewFieldInference {
const rawFields = [];
for (const [name, column] of Object.entries(columns)) {
const inferResult: any = { name, rawType: column.type };
const inferResult: any = { name, rawType: column.type, field: name };
const usage = columnUsage[name];

View File

@ -450,7 +450,7 @@ describe('view collection', function () {
const dropViewSQL = `DROP VIEW IF EXISTS test_view`;
await db.sequelize.query(dropViewSQL);
const viewSQL = `CREATE VIEW test_view AS select 1+1 as "Uppercase"`;
const viewSQL = `CREATE VIEW test_view AS select 1+1 as "t_Uppercase"`;
await db.sequelize.query(viewSQL);
await collectionRepository.create({
@ -458,7 +458,7 @@ describe('view collection', function () {
name: 'view_collection',
viewName: 'test_view',
isView: true,
fields: [{ type: 'string', name: 'upper_case', field: 'Uppercase' }],
fields: [{ type: 'string', name: 'upper_case', field: 't_Uppercase' }],
schema: db.inDialect('postgres') ? 'public' : undefined,
},
context: {},
@ -466,7 +466,7 @@ describe('view collection', function () {
const viewCollection = db.getCollection('view_collection');
expect(viewCollection.model.rawAttributes['upper_case'].field).toEqual('Uppercase');
expect(viewCollection.model.rawAttributes['upper_case'].field).toEqual('t_Uppercase');
const results = await viewCollection.repository.find();
expect(results.length).toBe(1);
});