-
Notifications
You must be signed in to change notification settings - Fork 2k
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
[Feature Request] callback afterFind #5471
[Feature Request] callback afterFind #5471
Comments
This has also been discussed in #525 (comment). @aclave1, would you be interested in taking this? I think this is a good fit for cc: @randallmeeker |
+1 for v0.11 |
One minute I think this should go into sails another min I think it should go into waterline. But definitely it should go somewhere!! |
@jurajpetrik for your particular use case have you considered an attribute function, something along the lines of: //in some model
attributes: {
date:...
//...
hasExpired: function (){ return this.date < new Date();}
} Or is it that you want it to be sent over |
@dmarcelino I can take this. When should I get this done by? |
How about 0.11? There is no scheduled date yet... And thanks! |
@anasyb Thanks I didn't know about attribute functions, I do want it to be sent over res though. |
Then maybe you have two options: //api/controllers/EventController.js
module.exports = {
findOne: function( req, res ) {
var eventId;// = bla bla.. get it from req or from wherever you're getting it!
Event.findOne(eventId).exec(function(err, eve){
if ( err ) return res.serverError( err );
if ( !eve ) return res.notFound( 'No event found with ID ' + eventId );
var eveObj = eve.toObject();
//temp workaround for https://github.com/balderdashy/waterline/issues/891#issuecomment-88361748
eveObj.toJSON = undefined;
eveObj.hasExpired = eve.hasExpired();//assuming you've implemented hasExpired as an attr func
res.ok(eveObj);//bye bye darling
});
}
}; option 2. override toJSON in your model to add all that fancy stuff. This is a good option if you always want to add that attr to the json of your event. You can find an example of overriding Good luck! |
Thanks for posting, @jurajpetrik. I'm a repo bot-- nice to meet you! It has been 60 days since there have been any updates or new comments on this page. If this issue has been resolved, feel free to disregard the rest of this message. On the other hand, if you are still waiting on a patch, please:
Thanks so much for your help! |
Reopening since this is a feature request in a current milestone. |
+1 👍 |
Thanks for posting, @jurajpetrik. I'm a repo bot-- nice to meet you! It has been 30 days since there have been any updates or new comments on this page. If this issue has been resolved, feel free to disregard the rest of this message. On the other hand, if you are still waiting on a patch, please:
Thanks so much for your help! |
Hi all, is there any update on the status of this feature? An afterFind callback would be really useful for me. Thanks! |
An afterFind lifecycle callback would be really useful for me too! |
+1 |
1 similar comment
+1 |
@mikermcneil @raqem PR created for this balderdashy/waterline#1610 cheers |
Would it be possible to implement a callback afterFind? E.g. I have an event with a date specified and in afterFind I could insert an attribute hasExpired..
The text was updated successfully, but these errors were encountered: