Skip to content

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

Description

@akhilsky

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions