fix: get pg view def (#1641)
* fix: get pg view def * chore: console.log
This commit is contained in:
parent
bec624eb54
commit
86abc251d9
@ -56,9 +56,7 @@ export default class PostgresQueryInterface extends QueryInterface {
|
|||||||
|
|
||||||
const viewDefQuery = await this.db.sequelize.query(
|
const viewDefQuery = await this.db.sequelize.query(
|
||||||
`
|
`
|
||||||
SELECT viewname, definition
|
select pg_get_viewdef(format('%I.%I', '${schema}', '${viewName}')::regclass, true) as definition
|
||||||
FROM pg_views
|
|
||||||
WHERE schemaname = '${schema}' AND viewname = '${viewName}';
|
|
||||||
`,
|
`,
|
||||||
{ type: 'SELECT' },
|
{ type: 'SELECT' },
|
||||||
);
|
);
|
||||||
@ -71,10 +69,19 @@ WHERE schemaname = '${schema}' AND viewname = '${viewName}';
|
|||||||
const usages = columns
|
const usages = columns
|
||||||
.map((column) => {
|
.map((column) => {
|
||||||
const fieldAlias = column.as || column.expr.column;
|
const fieldAlias = column.as || column.expr.column;
|
||||||
const columnUsage = columnUsages.find(
|
const columnUsage = columnUsages.find((columnUsage) => {
|
||||||
(columnUsage) =>
|
let columnExprTable = column.expr.table;
|
||||||
columnUsage.column_name === column.expr.column && columnUsage.table_name === column.expr.table,
|
|
||||||
);
|
// handle column alias
|
||||||
|
const from = ast[0].from;
|
||||||
|
const findAs = from.find((from) => from.as === columnExprTable);
|
||||||
|
|
||||||
|
if (findAs) {
|
||||||
|
columnExprTable = findAs.table;
|
||||||
|
}
|
||||||
|
|
||||||
|
return columnUsage.column_name === column.expr.column && columnUsage.table_name === columnExprTable;
|
||||||
|
});
|
||||||
|
|
||||||
return [
|
return [
|
||||||
fieldAlias,
|
fieldAlias,
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import Database, { Collection as DBCollection } from '@nocobase/database';
|
import Database, { Collection as DBCollection, HasManyRepository } from '@nocobase/database';
|
||||||
import Application from '@nocobase/server';
|
import Application from '@nocobase/server';
|
||||||
import { createApp } from '.';
|
import { createApp } from '.';
|
||||||
import CollectionManagerPlugin, { CollectionRepository } from '@nocobase/plugin-collection-manager';
|
import CollectionManagerPlugin, { CollectionRepository } from '@nocobase/plugin-collection-manager';
|
||||||
@ -605,4 +605,78 @@ describe('collections repository', () => {
|
|||||||
|
|
||||||
expect(err).toBeFalsy();
|
expect(err).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should update association field', async () => {
|
||||||
|
const A = await Collection.repository.create({
|
||||||
|
values: {
|
||||||
|
name: 'a',
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
name: 'title',
|
||||||
|
type: 'string',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'bs',
|
||||||
|
type: 'hasMany',
|
||||||
|
uiSchema: {
|
||||||
|
title: 'bs-title',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
context: {},
|
||||||
|
});
|
||||||
|
|
||||||
|
const B = await Collection.repository.create({
|
||||||
|
values: {
|
||||||
|
name: 'b',
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
type: 'string',
|
||||||
|
name: 'title',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'belongsTo',
|
||||||
|
name: 'a',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
uiSchema: {
|
||||||
|
title: 'b-title',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
context: {},
|
||||||
|
});
|
||||||
|
|
||||||
|
const C = await Collection.repository.create({
|
||||||
|
values: {
|
||||||
|
name: 'c',
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
type: 'string',
|
||||||
|
name: 'title',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'belongsTo',
|
||||||
|
name: 'a',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
uiSchema: {
|
||||||
|
title: 'c-title',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
context: {},
|
||||||
|
});
|
||||||
|
|
||||||
|
await db.sync();
|
||||||
|
|
||||||
|
await db.getRepository<HasManyRepository>('collections.fields', 'c').update({
|
||||||
|
filterByTk: 'a',
|
||||||
|
values: {
|
||||||
|
key: C.key,
|
||||||
|
uiSchema: {
|
||||||
|
title: 'c-hello-world',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user