mirror of
https://github.com/strapi/strapi.git
synced 2025-10-17 11:08:14 +00:00
Update user bookshelf fetch query
This commit is contained in:
parent
baa2f92040
commit
44c511ad50
@ -2,11 +2,21 @@ const _ = require('lodash');
|
||||
|
||||
module.exports = {
|
||||
find: async function (params) {
|
||||
return await this
|
||||
.forge()
|
||||
.fetchAll({
|
||||
withRelated: this.associations.map(x => x.alias)
|
||||
return Article.query(function(qb) {
|
||||
_.forEach(params.where, (where, key) => {
|
||||
qb.where(key, where.symbol, where.value);
|
||||
});
|
||||
|
||||
if (params.sort) {
|
||||
qb.orderBy(params.sort);
|
||||
}
|
||||
|
||||
qb.offset(params.start);
|
||||
|
||||
qb.limit(params.limit);
|
||||
}).fetchAll({
|
||||
withRelated: _.keys(_.groupBy(_.reject(this.associations, {autoPopulate: false}), 'alias'))
|
||||
});
|
||||
},
|
||||
|
||||
count: async function (params) {
|
||||
@ -16,10 +26,13 @@ module.exports = {
|
||||
},
|
||||
|
||||
findOne: async function (params) {
|
||||
if (_.get(params, 'where._id')) {
|
||||
params.where.id = params.where._id;
|
||||
delete params.where._id;
|
||||
}
|
||||
|
||||
const record = await this
|
||||
.forge({
|
||||
[this.primaryKey]: params[this.primaryKey]
|
||||
})
|
||||
.forge(params.where)
|
||||
.fetch({
|
||||
withRelated: this.associations.map(x => x.alias)
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user