var bookshelf = require('bookshelf')(knex); bookshelf.plugin('pagination'); const ArticuloImagen = bookshelf.Model.extend({ tableName: 'ARTICULOS_IMAGEN' }); const Articulo = bookshelf.Model.extend({ tableName: 'ARTICULOS', imagenes: function () { return this.hasMany(ArticuloImagen, 'id_articulo', 'id'); } }); router.post('/articulos', (req, res) => { Articulo .query((qb) => { qb.where(`DET_LAR`, `like`, `%${req.body.search}%`); }) .orderBy('id') .fetchPage({ pageSize: 150, page: req.body.page, withRelated: ['imagenes'] }) .then(data => { res.status(200).send( { data: data, pagination: data.pagination, }); }); }); module.exports = router;