Skip to content

Error in Relationships code #29

@ee0pdt

Description

@ee0pdt

In the following code I believe self.$hasMany should be self.$hasOne

    for(var rel in self.$hasOne) {
        if(rel === name) {
            self[rel] = self.$mapping[rel]();

            var id = self[self.$hasMany[rel].id]; //mandatory
            var field = self.$hasMany[rel].field || null;

            return self[rel].$get(id,field);
        }
    }

Also, I am getting the following error when trying to use this code:

TypeError: Cannot read property 'apply' of undefined

line of code that throws the error is:

  self[rel] = self.$mapping[rel]();

My User model:

return ModelCore.instance({
    $type : "Users", //Define the Object type
    $pkField : "id", //Define the Object primary key
    $mapping : {
      id : null,
      Profiles : Profiles,
    },
    $hasOne : { // Define Relations
      Profiles : {
        id : "id",
        field : "user_id" //field to be searched on Profile model
      }
    },

My Profile model:

return ModelCore.instance({
    $type : "Profiles", //Define the Object type
    $pkField : "id", //Define the Object primary key
    $mapping : {
      id : null,
      user_id : null
    },

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