问题描述
我想再增加一列,并从另一列修改后的值: 现在,我有了下一个这样的代码,但是它不起作用:
const { Model } = require("objection");
class TestModel extends Model {
static get tableName() {
return "testTable";
}
static get virtualAttributes() {
return ["someNewField"];
}
someNewField() {
return this.someField+'testString';
}
static get jsonSchema() {
return {
type: "object",properties: {
someField:{ type: "string" },},};
}
}
module.exports = {
TestModel,};
我遇到类似的错误
"message": "Cannot query field \"someNewField\" on type \"testTable\".",
我的grapql查询:
{TestModels{
someNewField,}
解决方法
从数据库中提取数据后,将在javascript端创建虚拟属性。因此,不会为数据库生成名为someNewField
的列。
因此,现在您尝试创建一个查询,尝试从根本不存在的数据库中查找数据。
没有通用的解决方法来使这项工作。如果您可以在这里解释用例的目的,那么我可能会建议在该特定情况下可以做的事情。