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(
|
||||
`
|
||||
SELECT viewname, definition
|
||||
FROM pg_views
|
||||
WHERE schemaname = '${schema}' AND viewname = '${viewName}';
|
||||
select pg_get_viewdef(format('%I.%I', '${schema}', '${viewName}')::regclass, true) as definition
|
||||
`,
|
||||
{ type: 'SELECT' },
|
||||
);
|
||||
@ -71,10 +69,19 @@ WHERE schemaname = '${schema}' AND viewname = '${viewName}';
|
||||
const usages = columns
|
||||
.map((column) => {
|
||||
const fieldAlias = column.as || column.expr.column;
|
||||
const columnUsage = columnUsages.find(
|
||||
(columnUsage) =>
|
||||
columnUsage.column_name === column.expr.column && columnUsage.table_name === column.expr.table,
|
||||
);
|
||||
const columnUsage = columnUsages.find((columnUsage) => {
|
||||
let columnExprTable = 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 [
|
||||
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 { createApp } from '.';
|
||||
import CollectionManagerPlugin, { CollectionRepository } from '@nocobase/plugin-collection-manager';
|
||||
@ -605,4 +605,78 @@ describe('collections repository', () => {
|
||||
|
||||
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