mirror of
https://github.com/nocodb/nocodb.git
synced 2026-02-01 23:48:33 +00:00
fix: read api - extract dependency fields, use it to generate select query and avoid duplicate use of nocoExecute
Signed-off-by: Pranav C <pranavxc@gmail.com>
This commit is contained in:
@@ -12,4 +12,4 @@
|
||||
</envs>
|
||||
<method v="2" />
|
||||
</configuration>
|
||||
</component>
|
||||
</component>
|
||||
|
||||
@@ -130,10 +130,24 @@ class BaseModelSqlv2 {
|
||||
autoBind(this);
|
||||
}
|
||||
|
||||
public async readByPk(id?: any, validateFormula = false): Promise<any> {
|
||||
public async readByPk(
|
||||
id?: any,
|
||||
validateFormula = false,
|
||||
query: any = {},
|
||||
): Promise<any> {
|
||||
const qb = this.dbDriver(this.tnPath);
|
||||
|
||||
await this.selectObject({ qb, validateFormula });
|
||||
const { ast, dependencyFields } = await getAst({
|
||||
query,
|
||||
model: this.model,
|
||||
view: this.viewId && (await View.get(this.viewId)),
|
||||
});
|
||||
|
||||
await this.selectObject({
|
||||
...(dependencyFields ?? {}),
|
||||
qb,
|
||||
validateFormula,
|
||||
});
|
||||
|
||||
qb.where(_wherePk(this.model.primaryKeys, id));
|
||||
|
||||
@@ -153,14 +167,7 @@ class BaseModelSqlv2 {
|
||||
data.__proto__ = proto;
|
||||
}
|
||||
|
||||
// retrieve virtual column data as well
|
||||
const project = await Project.get(this.model.project_id);
|
||||
const { model, view } = await getViewAndModelByAliasOrId({
|
||||
projectName: project.title,
|
||||
tableName: this.model.title,
|
||||
});
|
||||
const { ast } = await getAst({ model, view });
|
||||
return data ? await nocoExecute(ast, data, {}) : {};
|
||||
return data ? await nocoExecute(ast, data, {}, query) : {};
|
||||
}
|
||||
|
||||
public async exist(id?: any): Promise<any> {
|
||||
|
||||
@@ -221,15 +221,13 @@ export class DatasService {
|
||||
dbDriver: await NcConnectionMgrv2.get(base),
|
||||
});
|
||||
|
||||
const row = await baseModel.readByPk(param.rowId);
|
||||
const row = await baseModel.readByPk(param.rowId, false, param.query);
|
||||
|
||||
if (!row) {
|
||||
NcError.notFound('Row not found');
|
||||
}
|
||||
|
||||
const { ast } = await getAst({ model, query: param.query, view });
|
||||
|
||||
return await nocoExecute(ast, row, {}, param.query);
|
||||
return row;
|
||||
}
|
||||
|
||||
async dataExist(param: PathParams & { rowId: string; query: any }) {
|
||||
@@ -637,13 +635,16 @@ export class DatasService {
|
||||
dbDriver: await NcConnectionMgrv2.get(base),
|
||||
});
|
||||
|
||||
const { ast } = await getAst({ model, query: param.query });
|
||||
const { ast, dependencyFields } = await getAst({
|
||||
model,
|
||||
query: param.query,
|
||||
});
|
||||
|
||||
return await nocoExecute(
|
||||
ast,
|
||||
await baseModel.readByPk(param.rowId),
|
||||
{},
|
||||
await baseModel.readByPk(param.rowId, false),
|
||||
{},
|
||||
dependencyFields,
|
||||
);
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
|
||||
Reference in New Issue
Block a user