0

我正在使用 waterline 和 waterlinhe-orientdb。我有用户和订单顶点类并购买了边缘类用户---已购买-->订单我正在尝试应用 Where 标准来填充。但不适用于填充。这是我的代码

var CREDIT_CARD = 1; 
User.find({id:userid}).populate('boughts',{where:{payment_method:CREDIT_CARD}})

架构

USER = {
    identity: 'user',
    connection: 'myLocalOrient',
    attributes:{
    status: { type:"integer", columnName:"status"},
    fname: { type:'string'},
    lname: { type:'string'},
    boughts: {collection: 'orders',through: 'boughts',via: 'user',dominant: true}
};

Bought = {
    identity:'boughts',
    connection: 'myLocalOrient',
    attributes:{
        status:{type:'integer', columnName:'status'},
        buyers:{
                  columnName: 'out',
                  type: 'string',
                  foreignKey: true,
                  references: 'users',
                  on: 'id',
                  onKey: 'id',
                  via: 'orders'
        },
        orders:{
                  columnName: 'in',
                  type: 'string',
                  foreignKey: true,
                  references: 'orders',
                  on: 'id',
                  onKey: 'id',
                  via: 'buyer'
        }
      }
};

Order = {
    identity:'orders',
    connection: 'myLocalOrient',
    attributes:{
            status:{type:'integer',columnName:'status'},
            payment_method:{type:'integer', columnName:'payment_method'},
            boughts:{collection:'users', through:'boughts',via:'orders'}
    }

};
4

1 回答 1

0

9me, from your model definition I can see you are using many-to-many through associations which are not yet officially supported by Waterline. This means that some functionality may not be fully operational and that some errors may occur. For more details read When Many-to-Many Through Associations release? #705.

Your query is also not correct:

var CREDIT_CARD = 1; 
User.find({id:userid}).populate('boughts',{where:{payment_method:CREDIT_CARD}})

The criteria in .populate() does not take the key where.

Here's an example from the documentation:

// Collection Filtering
User.find()
.populate('foo', { type: 'bar', limit: 20 })
.exec(function(err, users) {});

So, in your case you should use:

var CREDIT_CARD = 1; 
User.find({ id: userid }).populate('boughts', { payment_method: CREDIT_CARD })
于 2015-04-01T14:49:06.087 回答