Skip to content
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

Static methods are automatically bound with the context of their Model. #361

Merged
merged 1 commit into from
Jun 13, 2018

Conversation

DanielBoa
Copy link
Contributor

@DanielBoa DanielBoa commented May 22, 2018

This change automatically binds any applied static methods with the Model as the context. This is useful when passing a static method as a reference (for example to an array method).

e.g.

const userSchema = new Schema({ ... });

userSchema.statics.getById = function getUserById(id) {
  return this.queryOne('id').eq(id).exec();         
};

const User = dynamoose.model('User', userSchema);
const userIds = ['xxxx', 'yyyy'];
const users = await Promise.all(userIds.map(User.getById));

…pplied to. Added test for bound static methods.
@coveralls
Copy link

coveralls commented May 22, 2018

Coverage Status

Coverage remained the same at 82.495% when pulling 60d9497 on DanielBoa:master into 310da5c on automategreen:master.

Copy link
Member

@fishcharlie fishcharlie left a comment

Choose a reason for hiding this comment

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

LGTM

@fishcharlie
Copy link
Member

@DanielBoa Thanks for this! We'll get this in for version 0.9.

@fishcharlie fishcharlie added this to the v0.9.0 milestone May 25, 2018
@fishcharlie fishcharlie modified the milestones: v0.9.0, v1.0 Jun 13, 2018
@fishcharlie fishcharlie mentioned this pull request Jun 13, 2018
@fishcharlie fishcharlie merged commit af57ba6 into dynamoose:master Jun 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants