Model.fetchAll() is not firing fetching / fetched events
See original GitHub issueI’ve come up with the use of event capture with model.on. Capturing events: creating / created, updating / updated, destroying / destroyed, but I can not fetch fetched / fetched from the model when executing fetchAll (). I’ve only proven that when I run fetch () from the model I catch the fetching / fetched events.
Into my model:
constructor: function() {
bookshelf.Model.apply(this, arguments);
// When trying to retrieve records (SELECT)
this.on("fetching", function(model, attributes, options) {
//options.query.where('type ', ' = ', ' user ');
// Audit SELECT Queries in Model
console.log('\nYou try to query user information ... \n');
})
// Successfully retrieve records (SELECT)
this.on("fetched", function(model, attributes, options) {
//options.query.where('type ', ' = ', ' user ');
// Audit SELECT Queries in Model
console.log('\nUser information is successfully consulted \n');
})
Into my controller:
list: function list(req, res) {
return userModel.fetchAll().then(function(records) {
res.status(200).json(registers);
}).catch(function(err) {
res.status(400).json(err);
})
},
find: function find(req, res) {
return userModel
.forge('id', req.params.id).fetch()
.then(function(record) {
res.status (200).json(record);
}).catch(function(err) {
res.status(400).json (err);
})
}
Issue Analytics
- State:
- Created 7 years ago
- Reactions:4
- Comments:6 (1 by maintainers)
Top Results From Across the Web
API Reference - Bookshelf.js
This method is similar to Model#fetchAll , but fetches a single page of results as specified by the limit (page size) and offset...
Read more >Why is my fetch request not executing inside an event listener ...
When I call the fetch request function it logs to the console just fine, but as soon as I wrap it in an...
Read more >Querying Data from a Database using fetchone() and fetchall()
The method only returns the first row from the defined table and If there are no tuples then it returns an empty list...
Read more >fetch collection of records - Zoho
It is advisable to fetch all records only when absolutely needed. Fetching all records generates a load resulting in performance issues.
Read more >A comprehensive guide to data fetching in React
We'll demonstrate how to fetch data in React, complete with code examples, ... triggered a GET API request since we invoked fetch with...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’m also having the same issue, where I’m trying to run the following code in my model, in order to add another property to the response. The property relies on the
fetched
event which doesn’t fire when using thefetchAll
method, but does run withfetch
method.The reason is that fetching event refers to the models. Use “fetching:collection” instead for fetchAll.