Skip to content

TypeError: Cannot read property 'id' of null #116

@metsehaf

Description

@metsehaf

Hi I was trying to run a test where passing a parameter id to a function will give me a promise, I was using sequelize fixtures to load my test data. JobID, in this case, is a foreign key in the File model and below is the dummy data in my files.fixtures.json. I have added both job and file JSON since they have 1 to many relationships, Any help would be appreciated:

Json Data

[ { "model": "Job", "data": { "id": 2860, "jobType": "soil", "clientID": 2, "client": "devron", "fieldID": 5, "field": "eastern Ontario", "targetDate": "2019-06-01", "statusCode": "Queued", "legacyJobID": "string", "cropID": 3 } }, { "model": "File", "data": { "id": 1, "jobID": 2860, "job": 2860, "fieldID": 3, "field": "IField", "filename": "S3 2678.zip", "originalFilename": "S3 2678.zip", "addedBy": 4, "dateAdded": "2018-06-01", "filetype": "zip", "imageType": "ZIP" } } ]

And the error is being raised in the loader.js file in the sequelize package here:
` if (assoc) {
if (assoc.associationType === 'BelongsTo') {
var where = {};
where[assoc.target.primaryKeyField] = val;

            var options = typeof val === 'object' ? { where: val } : { where: where };
            if (self.options.transaction)
                options.transaction = self.options.transaction;
            promises.push(
                assoc.target.findOne(options)
                .then(function(obj) {
                    result[assoc.identifier] = obj[assoc.target.primaryKeyField || 'id'];
                    return Promise. esolve();
                })
            );`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions