加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – 在嵌套模型上使用populate从Angular.js到Sails.js

发布时间:2020-12-17 16:56:54 所属栏目:安全 来源:网络整理
导读:在我的Sails.js中,我有一个名为Invoices.js的模型,其结构如下: module.exports = { tableName:'invoices',adapter: 'mysql',autoPK:false,autoCreatedAt: true,autoUpdatedAt: true,attributes: { id: {type: 'integer',autoIncrement: true,primaryKey: tr
在我的Sails.js中,我有一个名为Invoices.js的模型,其结构如下:

module.exports = {

    tableName:'invoices',adapter: 'mysql',autoPK:false,autoCreatedAt: true,autoUpdatedAt: true,attributes: {

    id: {type: 'integer',autoIncrement: true,primaryKey: true},doc_mod: {type:'string'},doc_n: {type:'integer'},createdAt: {type:'date'},updatedAt: {type:'date'},settled: {type:'integer'},invoice_line: {collection:'invoice_lines',via:'invoice'},customer: {model:'customers'},booking:{collection:'bookings',via:'invoice'}
  }
}

我想从Angular.js查询通过’姓名’或’姓氏’找到客户,在客户端我想出了这个:

.factory('PaymentsService',['$resource',function($resource){

        return{

            Query:function(cursor,sorting,name,surname){
                var allPayments = $resource('http://localhost:1337/invoices');
                return allPayments.query({populate:{'customers':{where:{or:[{name:{contains:name}},{surname:{contains:surname}}]}}},skip:cursor,limit:100,sort:sorting}).$promise;
            }
}

它似乎不能正常工作我总是得到这个不完整和正确的结果:

.....{
"customer": 1,"id": 4,"doc_mod": "receipt","doc_n": 3,"createdAt": "2015-05-11T17:07:40.000Z","updatedAt": "2015-05-11T17:07:40.000Z","settled": 0
},{
"customer": 1,"id": 5,"doc_n": 4,"createdAt": "2015-05-11T18:26:55.000Z","updatedAt": "2015-05-11T18:26:55.000Z","settled": 0
}.....

解决方法

您目前无法以这种方式查询子文档.您需要撤消查询,以便过滤客户,然后返回关联的发票.它可能不是你想要的100%,但是水线正在解决这个问题!

var allPayments = $resource('http://localhost:1337/customers');

allPayments.query({
  where:{or:[{name:{contains:name}},{surname:contains:surname}}]},populate:'invoices',sort:sorting
})
.$promise

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读