简体   繁体   中英

SailsJS V1 - Blueprint query not working correctly

I'm trying to create a blueprint query for a sailsjs v1 model.

The model is a BlogPost which has 2 "options". One is the target and the other one is Status.

If the target is Site and the status is Published, the query should return, otherwise nope. I'm using the default REST routes provided by Sails (blueprints) and everything works fine if I try to find all of them. However, if I try to find one by ID...I can't even get back those that have a status of 'Unpublished'.

This is my code in blueprint.js parseBlueprintOptions ->

parseBlueprintOptions: function (req) {

    var queryOptions = req._sails.hooks.blueprints.parseBlueprintOptions(req);
    if (queryOptions.using === 'blogpost') {
      if (req.options.blueprintAction === 'create') {
        queryOptions.newRecord.user_id = req.session.user.id;
        return queryOptions;
      } else if (req.options.blueprintAction === 'update') {
        queryOptions.criteria.where.user_id = req.session.user.id;
        queryOptions.valuesToSet.user_id = req.session.user.id;
        return queryOptions;
      } else {
        if (req.session.administrator) {
          return queryOptions;
        } else {
          queryOptions.criteria.where.blogpost_target = 'Site';
          queryOptions.criteria.where.blogpost_status = 'Published';

          console.log(queryOptions);
          return queryOptions;
        }
      }
    }
  }
};

Any tips on why the query does not get triggered for findOne ? As i said, it returns regardless of the status/target.

Hey 'find' returns object array and 'findone' returns only an object . I guess therefor it won't work!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM