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

MySQL connecter error #5

Open
maxfi opened this issue Sep 15, 2015 · 3 comments
Open

MySQL connecter error #5

maxfi opened this issue Sep 15, 2015 · 3 comments

Comments

@maxfi
Copy link

maxfi commented Sep 15, 2015

I tried to use this mixin and can't get it to work with the following setup:

server/server.js

var loopback = require('loopback');
var boot = require('loopback-boot');

// Otherwise Promise.map doesn't work.
global.Promise = require('bluebird');

var app = module.exports = loopback();

require('loopback-ds-computed-mixin')(app);

app.start = function() {
  // start the web server
  return app.listen(function() {
    app.emit('started');
    console.log('Web server listening at: %s', app.get('url'));
  });
};

// Bootstrap the application, configure models, datasources and middleware.
// Sub-apps like REST API are mounted via boot scripts.
boot(app, __dirname, function(err) {
  if (err) throw err;

  // start the server if `$ node server.js`
  if (require.main === module)
    app.start();
});

common/models/myModel.json

{
  "name": "MyModel",
  "options": {
    "idInjection": false,
    "mysql": {
      "schema": "someSchema",
      "table": "myModel"
    }
  },
  "properties": {
    "description": "String"
  },
  "mixins": {
    "Computed": {
      "properties": {
        "description": "computedDescription"
      }
    }
  }
}

common/models/myModel.js

module.exports = function(MyModel) {
  MyModel.computedDescription = function(myModel) {
    return "some description";
  };
};

When I try to GET /api/MyModels I get an error from the mysql connector saying it can't find the description field.

@beeman
Copy link
Contributor

beeman commented Sep 15, 2015

I haven't tried this with the MySQL connector. It might help if you add the description field to the table if it's not there yet.

@stringbeans
Copy link

I have the same issue. The solution of adding the column to the table doesn't make sense since its a computed property (ie. it shouldnt be a real column)

@Akeri
Copy link

Akeri commented Dec 2, 2017

Sorry to be late. I faced this issue recently and solved it by setting global "scope" in the model JSON definition like this:

"scope": { "fields": { "description": false } }

I hope this can still help someone

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

4 participants