vendredi 17 avril 2015

BookshelfJS return multiple pivot for BelongsToMany

I have two tables: patches and devices. The relationship here is many-to-many, and so I have a pivot table of pivot_device_patch.


The pivot table also has a column status that can be available, failed, success. There can be multiple of the same patch available for the device (i.e. the first one fails, so you create another request until it becomes successful).


I want to get all the instances of the pivot table, so I know how many has been pushed to the device. My query so far is:



new Device({guid : req.params.boxGuid})
.fetch({withRelated: ['patches', {
'patches' : function (qb) {
qb.where('guid', '=', req.params.patchGuid);
}
}]
}).then(function (device) {
res.json(device);
})


But this returns the very first entry in the pivot. How do I return ALL of them?


Aucun commentaire:

Enregistrer un commentaire