0

I am using waterline and waterlinhe-orientdb. I have user and order vertex classes and bought edge class User ---Bought-->Orders I am trying to apply Where criteria on populate. But is not working on populate. Here is my code

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

Schema

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'}
    }

};
Travis Webb
  • 14,688
  • 7
  • 55
  • 109
9me
  • 1,078
  • 10
  • 36

1 Answers1

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 })
Dário
  • 2,002
  • 1
  • 18
  • 28
  • Thanks. I'll Try it. and I have an other question How can I run this query in waterline `SELECT COUNT(@rid), SUM(total_amount) FROM bills` ? Thanks again – 9me Apr 01 '15 at 18:56