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

Add example of how to use custom collections #2015

Merged
merged 2 commits into from Sep 12, 2019

Conversation

@ricardograca
Copy link
Member

commented Sep 10, 2019

Introduction

Document how to use a custom collection for the results of every call to .fetchAll(). This includes calls to .fetchPage() and .related() as well, in case the relation is a one to many. Basically any time a new collection of the Model is created.

Motivation

Collections are a bit hard to understand. This should help users that want to attach custom behavior to the collections associated with a certain model.

Currently a new anonymous collection is created when trying to compose the results of a .fetchAll(), but it's sometimes useful to add extra behavior to this collection in a predictable way.

Fixes #1466.

@ricardograca ricardograca added the docs label Sep 10, 2019
@fl0w

This comment has been minimized.

Copy link
Collaborator

commented Sep 10, 2019

Let me know if you need anything, I feel pretty versed at this point regarding collections and the inner workings of bookshelf.

@ricardograca

This comment has been minimized.

Copy link
Member Author

commented Sep 11, 2019

Thanks. Can you take a look at the changes here and see if the new documentation is good enough?

@fl0w
fl0w approved these changes Sep 11, 2019
Copy link
Collaborator

left a comment

Nice! This looks good IMO. Small addition if it's to taste.
I haven't tried master with registry promoted to core yet though.

lib/collection.js Show resolved Hide resolved
@ricardograca ricardograca merged commit 681c262 into master Sep 12, 2019
2 checks passed
2 checks passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details
@ricardograca ricardograca deleted the rg-collection-docs branch Sep 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.