Skip to content
This repository was archived by the owner on Jun 20, 2023. It is now read-only.

beforeFind callback#2

Closed
matt-cook wants to merge 2 commits into0.10.xfrom
0.10.x-beforeFind
Closed

beforeFind callback#2
matt-cook wants to merge 2 commits into0.10.xfrom
0.10.x-beforeFind

Conversation

@matt-cook
Copy link

Duplicate of balderdashy#902 against current 0.10.x branch.


this.beforeCallbacks.call(self,criteria.where,function(err){
if (err) {return cb(err);}
});

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code flow here is so weird. Basically, we could have cb called more than once, if one of the beforeCallbacks returns an error. I know it's how they do it in the original waterline PR, but feels totally bizarre. Can't help but wonder if there's a better way to do it, but also don't want to get too far away from how they do things normally with waterline.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at how beforeDestroy and beforeUpdate work, the code flow is much nicer. They appropriately handle all async callbacks and such. It feels like the right thing to do would be to put everything after this inside the callback. That way folks could do async operations if they wanted to.

Would up the line count change significantly, but would just be indentation.


this.beforeCallbacks.call(self,criteria.where,function(err){
if (err) return cb(err);
})

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing ;

});
},

beforeCallbacks:function(criteria,cb){

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear to me why this function exists. All it does is call callbacks.beforeFind, but it's wrapped in this beforeCallbacks function that then wraps that one call in async.series. Is the idea that eventually there may be more than just beforeFind?

// Normalize criteria
criteria = normalize.criteria(criteria);

this.beforeCallbacks.call(self,criteria.where,function(err){

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, this guys first point is a problem I think. If no criteria is passed to Model.find then values will be null when it gets into the beforeFind callback.

balderdashy#902 (comment)

Might need to do criteria.where || {} or something like that...not totally sure of the implications there.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solution suggested here balderdashy#902 (comment)

@matt-cook
Copy link
Author

Functionally complete. However, closed in favor of: #3

@matt-cook matt-cook closed this Jan 24, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants