Sails.js 嵌套查询在SailsJs中不起作用

Sails.js 嵌套查询在SailsJs中不起作用,sails.js,waterline,Sails.js,Waterline,我想查询“所有项目,都有一个特定的成员” Project.js: module.exports = { attributes: { name: { type: "string" }, topics: { collection: "topic", via: "projects" }, profesor: { type: 'string' }, creator: {

我想查询“所有项目,都有一个特定的成员”

Project.js:

module.exports = {

  attributes: {

    name: {
        type: "string"
    },

    topics: {
        collection: "topic",
        via: "projects"
    },

    profesor: {
      type: 'string'
    },

    creator: {
      type: 'string' 
    },

    members: {
        collection: "user",
      via: "projects"
    },

    content: {
        collection: "content",
        via: "projectData"
    }

  }
};
User.js:

module.exports = {

  attributes: {

    projects: {
      collection:"project",
      via: "members",
      dominant: true
    },

    email: {
        type: 'email',
        required: true,
        unique: true
    },

    mat: {
      type: 'integer',
      required: true,
      unique: true
    },

    name: {
        type: 'string',
        required: true,
    },

    lastname: {
        type: 'string',
        required: true,
    },

    admin: {
      type: 'boolean'
    },


    encryptedPassword : {
        type: 'string'
    },

     toJSON: function() {
      var obj = this.toObject();
      delete obj.password;
      delete obj.encryptedPassword;
      delete obj.confirmation;
      delete obj._csrf;
      return obj;
    }

  },


  beforeValidate: function (values, next) {
    console.log(values);
    if (typeof values.admin !== 'undefined') {
      if (values.admin === 'unchecked') {
        values.admin = false;
      } else  if (values.admin[1] === 'on') {
        values.admin = true;
      }
    }
     next();
  },

  beforeCreate: function (values, next) {

    User.count().exec(function countCB(error, found) {
      if (found == 0) {
      values.admin = true;
      }
   });

    // This checks to make sure the password and password confirmation match before creating record
    if (!values.password || values.password != values.confirmation) {
      return next({err: ["Password doesn't match password confirmation."]});
    }

    require('bcrypt').hash(values.password, 10, function passwordEncrypted(err, encryptedPassword) {
      if (err) return next(err);
      values.encryptedPassword = encryptedPassword;
      // values.online= true;
      next();
    });
  }

};
这是我的问题:

index: function(req,res){
        Project.find().populate('members', {name: 'Hugo'}).exec(function(err, prj){
                if (err) res.negotiate(err);
                console.log("funciona esto?");
                console.log(prj);


                res.view({
                project: prj
                });
        });
    },

为什么不工作?这是所有的项目,有人能帮我吗?我不确定waterline是否允许这样做。

尝试获取用户,然后填充项目:

index: function(req,res){
        User
        .find({name: 'Hugo'})
        .populate('projects')
        .exec(function(err, user){
                if (err) res.negotiate(err);
                console.log("funciona esto?");
                console.log(user.projects);


                res.view({
                project: user.projects[0] // first project
                });
        });
    },

您的查询将转换为查找所有项目,并在成员名为“Hugo”的位置填充成员。您应该找到名为“Hugo”的所有成员的所有项目。