dovahkiin
dovahkiin

Reputation: 718

Error in SailsJs. TypeError: Cannot read property 'attributes' of undefined

I'm working with sailsjs and mongodb. I'm getting the error "TypeError: Cannot read property 'attributes' of undefined".

This are the models:

UserInterest.js

module.exports = {
  attributes: {
    id: {
      type: 'integer',
      primaryKey: true
    },

    name: { type: 'string' },

    profiles: { collection: 'UserProfile', via: 'interests'}
  }
};

UserProfile.js

module.exports = {
    attributes : {
        id : {
            type : 'string',
            autoIncrement : true,
            primaryKey : true
        },

        createdAt : {
            type : 'datetime'
        },

        updatedAt : {
            type : 'datetime'
        },

        user : {
            model : 'User'
        },

        sex : {
            type : 'integer'
        },

        interests : {
            collection : "UserInterest",
            via : "profiles",
            dominant : true
        }
        //Other attributes here
    }
};

I'm trying to get a user profile loaded this way:

UserProfile.findOne({user : id})
.populate("interests")
.exec(function(err, obj) {
    if (err) {
        cb(err, null);
    } else {
        cb(err, obj);
    }
});

The error happens in populate function. Why this is happening?

Upvotes: 1

Views: 2954

Answers (1)

dovahkiin
dovahkiin

Reputation: 718

After struggling a lot with this problem, I found an answer. The attribute interests was duplicated and sails was having problems with it. I eliminated the duplicate, leaving the collection definition.

Upvotes: 1

Related Questions