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

The PersistedModel has not been correctly attached to a datasource #19

Open
2 tasks
akhilsky opened this issue Jul 29, 2017 · 2 comments
Open
2 tasks

Comments

@akhilsky
Copy link

I am getting error: Error: Cannot call Test.create(). The create method has not been setup The PersistedModel has not been correctly attached to a datasource.

Here is my datasource.json:

{
  "db": {
    "name": "db",
    "connector": "memory"
  },
  "mongoDS": {
    "host": "localhost", 
    "port": 27017, 
    "name": "mongoDS",
    "database": "akhiltest",
    "connector": "mongodb"
  }
}

model-config.json:

{
  "_meta": {
    "sources": [
      "loopback/common/models",
      "loopback/server/models",
      "../common/models",
      "./models"
    ],
    "mixins": [
      "loopback/common/mixins",
      "loopback/server/mixins",
      "../common/mixins",
      "./mixins"
    ]
  },
  "User": {
    "dataSource": "db"
  },
  "AccessToken": {
    "dataSource": "db",
    "public": false
  },
  "ACL": {
    "dataSource": "db",
    "public": false
  },
  "RoleMapping": {
    "dataSource": "db",
    "public": false,
    "options": {
      "strictObjectIDCoercion": true
    }
  },
  "Role": {
    "dataSource": "db",
    "public": false
  },
  "Test": {
    "dataSource": "mongoDS",
    "public": true
  }
}

test.js

'use strict';

module.exports = function(Test) {
Test.create({
    "first_name":"akhil"
},function(data){
    console.log(data);
})
};

test.json

{
  "name": "Test",
  "base": "PersistedModel",
  "idInjection": true,
  "options": {
    "validateUpsert": true
  },
  "properties": {
    "first_name": {
      "type": "string"
    }
  },
  "validations": [],
  "relations": {},
  "acls": [],
  "methods": {}
}

Your help will be highly appreciated

Bug or feature request

  • Bug
  • Feature request

Description of feature (or steps to reproduce if bug)

Link to sample repo to reproduce issue (if bug)

Expected result

Actual result (if bug)

Additional information (Node.js version, LoopBack version, etc)

@Marwan01
Copy link

Marwan01 commented Aug 7, 2018

Hello. I have been having the same issue and I fixed it by getting rid of the whole
Test.create({ "first_name":"akhil" },function(data){ console.log(data); })
Try using the explorer instead at localhost:3000/explorer

If that doesn't solve it, try refactoring all instances of the variable db to mongoDS or the opposite.

@Marwan01
Copy link

@akhilsky lmk if this solved your issue!

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