Skip to content

Add example of how to use custom collections#2015

Merged
ricardograca merged 2 commits into
masterfrom
rg-collection-docs
Sep 12, 2019
Merged

Add example of how to use custom collections#2015
ricardograca merged 2 commits into
masterfrom
rg-collection-docs

Conversation

@ricardograca

Copy link
Copy Markdown
Member

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.

@fl0w

fl0w commented Sep 10, 2019

Copy link
Copy Markdown
Collaborator

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

@ricardograca

Copy link
Copy Markdown
Member Author

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

@fl0w fl0w left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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

Comment thread lib/collection.js
@ricardograca
ricardograca merged commit 681c262 into master Sep 12, 2019
@ricardograca
ricardograca deleted the rg-collection-docs branch September 12, 2019 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Understanding custom collections

2 participants