mirror of
https://github.com/strapi/strapi.git
synced 2025-10-19 12:02:38 +00:00
Update user bookshelf fetch query
This commit is contained in:
parent
baa2f92040
commit
44c511ad50
@ -2,10 +2,20 @@ const _ = require('lodash');
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
find: async function (params) {
|
find: async function (params) {
|
||||||
return await this
|
return Article.query(function(qb) {
|
||||||
.forge()
|
_.forEach(params.where, (where, key) => {
|
||||||
.fetchAll({
|
qb.where(key, where.symbol, where.value);
|
||||||
withRelated: this.associations.map(x => x.alias)
|
});
|
||||||
|
|
||||||
|
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'))
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -16,10 +26,13 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
findOne: async function (params) {
|
findOne: async function (params) {
|
||||||
|
if (_.get(params, 'where._id')) {
|
||||||
|
params.where.id = params.where._id;
|
||||||
|
delete params.where._id;
|
||||||
|
}
|
||||||
|
|
||||||
const record = await this
|
const record = await this
|
||||||
.forge({
|
.forge(params.where)
|
||||||
[this.primaryKey]: params[this.primaryKey]
|
|
||||||
})
|
|
||||||
.fetch({
|
.fetch({
|
||||||
withRelated: this.associations.map(x => x.alias)
|
withRelated: this.associations.map(x => x.alias)
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user