Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to implement virtual Attributes? #91

Open
vitalizis opened this issue Aug 26, 2020 · 1 comment
Open

How to implement virtual Attributes? #91

vitalizis opened this issue Aug 26, 2020 · 1 comment

Comments

@vitalizis
Copy link

I would like to have an additional column with a modified value from another column: Now I have next code like this but it doesn't work:

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,
    };

I got error like:
"message": "Cannot query field \"someNewField\" on type \"testTable\".",

@CassandraNewell
Copy link

I have a similar example working, but I had to add someNewField to the properties list in jsonSchema, and my someNewField() is a getter (not sure if the second part is important or just the first).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants