如何在帆js中使用子标准(例如:.populate('something',{select:[]})))>

问题描述 投票:0回答:1

.populate('something',{select:[]})) in sails js .对我来说是一个模棱两可的用法。是否有其他解决方法

我在填充中使用了select inside ...,但它表明子条件在此版本的帆中不起作用

Banktransaction.find(newData).populate('project_id',{select:['project_name']}).exec((err,banktrans)=>{
                                    if(err){
                                        return res.json({
                                            error : err
                                            });
                                        }   
                                        if(!banktrans){
                                            return res.notFound();
                                        }else{
                                            return res.json({
                                                'responseType':"success",
                                                'responseMessage':"Banktransaction details founded successfully",
                                                'result': banktrans
                                            });
                                        }



                                });

//result

{
    "error": {
        "name": "UsageError",
        "code": "E_INVALID_POPULATES",
        "details": "Could not populate `project_id` because of ambiguous usage.  This is a singular (\"model\") association, which means it never refers to more than _one_ associated record.  So passing in subcriteria (i.e. as the second argument to `.populate()`) is not supported for this association, since it generally wouldn't make any sense.  But that's the trouble-- it looks like some sort of a subcriteria (or something) _was_ provided!\n(Note that subcriterias consisting ONLY of `omit` or `select` are a special case that _does_ make sense.  This usage will be supported in a future version of Waterline.)\n\nHere's what was passed in:\n{ select: [ 'project_name' ] }"
    }
}

。populate('something',{select:[]})))在sails js中。对我来说,这是一种模棱两可的用法。对于我在内部使用select内部填充的问题,是否有其他解决方案,但是它显示子条件没有...

sails.js
1个回答
0
投票

您现在可能已经知道了,但是.populate()受限制,有时航行的文档是错误的。我专门编写了一个帮助程序来基于3rd-normal O2M / M2M关联表进行填充。我的方法还需要模型方法,这些方法提供每个关联的字段名称的基本配置以及对其模型类的引用。它不是很优美,它是对每条记录的单独查询,但也许您可能会对我的方法的某些细节感兴趣:

© www.soinside.com 2019 - 2024. All rights reserved.