articulos.js 704 Bytes
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.get('/articulos/:page', (req, res) => {

  Articulo
    .query(() => {})
    .orderBy('id')
    .fetchPage({
      pageSize: 150,
      page: req.params.page,
      withRelated: ['imagenes']
    })
    .then(data => {

      res.status(200).send(
        {
          data: data,
          pagination: data.pagination,
        });

    });
});

module.exports = router;