0

I have this three models:

{
  "name": "ExeboardUserBoard",
  "base": "PersistedModel",
  "idInjection": true,
  "options": {
    "validateUpsert": true
  },
  "properties": {},
  "validations": [],
  "relations": {
    "exeboardUser": {
      "type": "belongsTo",
      "model": "exeboardUser",
      "foreignKey": "exeboardUserId"
    },
    "board": {
      "type": "belongsTo",
      "model": "board",
      "foreignKey": "boardId"
    },
  },
  "acls": [],
  "methods": {}
}

Model: ExeboardUser

{
  "name": "ExeboardUser",
  "base": "User",
  "idInjection": true,
  "options": {
    "validateUpsert": true
  },
  "properties": {
    "name": {
      "type": "string",
      "required": true
    }
  },
  "validations": [],
  "relations": {
    "boards": {
      "type": "hasMany",
      "model": "Board",
      "foreignKey": "exeboardUserId",
      "through": "ExeboardUserBoard"
    }
  },
  "acls": [],
  "methods": {}
}

Model: Board

{
  "name": "Board",
  "plural": "Boards",
  "base": "PersistedModel",
  "idInjection": true,
  "options": {
    "validateUpsert": true
  },
  "properties": {
    "name": {
      "type": "string",
      "required": true
    }
  },
  "validations": [],
  "relations": {
    "users": {
      "type": "hasMany",
      "model": "ExeboardUser",
      "foreignKey": "boardId",
      "through": "ExeboardUserBoard"
    }
  },
  "acls": [],
  "methods": {}
}

I´m trying to prepopulate my db with a board having a single user. However I´m not able to access the board.users property. It gives me the error:

TypeError: Cannot read property 'type' of undefined

This is the code I have

var users = [
    {
      name: "test"

    }
  ];
  //Create Board
  function createBoard(cb){
    pgdb.automigrate('Board', function(err) {
      //if (err) return cb(err);
      var Board = app.models.Board;
      Board.create([
        {name:"Board 1"
        },
        {name:"Board 2"
        }

        ],function(err,boards){
          boards[0].users.add(users[0]);

      });

    });

    //Create ExeboardUser
  function createExeboardUser(cb){
    pgdb.automigrate('ExeboardUser', function(err) {
      //if (err) return cb(err);
      var ExeboardUser = app.models.ExeboardUser; 
        ExeboardUser.create(users,function(err,users){


        });
    });
  }
Cœur
  • 37,241
  • 25
  • 195
  • 267
Pablo Estrada
  • 3,182
  • 4
  • 30
  • 74

0 Answers0