-
Notifications
You must be signed in to change notification settings - Fork 568
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bulk updates without fetching/Related joins #402
Comments
This is intentional, as the join requires that you know all of the columns in advance, which bookshelf does not require, you'd need a good way of aliasing all of the columns such that there are no collisions, and then you'd need to iterate over the entire result set to deal with parsing/deduping the columns, which in javascript might actually be slower than dealing with the extra initial query. This is also how ActiveRecord generally deals with eager loading. By making it two separate queries, you also gain the ability to easily constrain the subqueries at different levels, a la: db.User()
.fetchAll({withRelated: [{
'roles': function(qb) {
qb.where('status', active);
}}, 'roles.info']
}).then(function (user) {
res.json(user);
}); which would provide: select * from `users`;
select * from `users_roles` where `users_roles`.`user_id` in (?, ?) and `status` = 'active'
select * from `info` where `role_id` in (?, ?, ?...) There will however be improvements in coming releases, and the ability to do better joins for constraints will be provided (and possibly a simple way of doing something like you mentioned).
Not with Bookshelf, you'd do it with knex... the User.query()
.where('lastLoginDate', '<', moment().toDate().subtract('d', '60'))
.update({enabled: false}).then(... |
@tgriesser would your update solution update the timestamps as well? So that if I did:
The |
@AntJanus |
It's been a pleasure using this library. It influenced me to promisify my entire code base which is much cleaner than using the async lib and node callbacks.
I just have two questions:
I noticed that relations are fetched one at a time:
The following would produce two queries:
instead of:
Is there a reason for this, or was this something that was planned in a future release?
Is it possible to do actual bulk updates:
The text was updated successfully, but these errors were encountered: