Understanding custom collections
See original GitHub issueIn my experience, collections are highly random. Even simple usage makes no sense to me.
class OtherModel extends bookshelf.Model {
get tableName () { return 'other_models' }
}
class MyModel extends bookshelf.Model {
get tableName () { return 'my_models' }
otherRelation () {
return this.hasMany(OtherModel)
}
}
class MyOtherCollection extends bookshelf.Collection {
get model () { return OtherModel }
}
MyModel
.forge({ id: 1 })
.otherRelation()
.fetch()
.then((myOtherModels) => {
console.log(myOtherModels instanceof bookshelf.Collection) // true
console.log(myOtherModels instanceof MyOtherCollection) // false
})
My question is, is this behaviour intended? If yes, I’m quite lost on how I should reason about collections in general.
Am I perhaps going about this wrong and completely missed a core principle?
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:10 (4 by maintainers)
Top Results From Across the Web
What Are Custom Collections? - Virtuous Support
In Virtuous, you can track data and values specific to your organization by using Custom Fields, and even group them together for clear......
Read more >4. Custom Collections for a Custom Library - Understanding System ...
In this chapter, you will learn the fundamental aspects of implementing custom collections using features and the organization required for any .
Read more >4 Reasons a Custom Collections Software benefit Your ...
Both out-of-the-box software and custom software have their own benefits. ... As a collections professional, you know and understand the collections process ...
Read more >CMS Collections - Webflow University
CMS Collections are content types with different structures in the Webflow ... structure by either choosing a template or adding custom collection fields....
Read more >Collections in Java - Everything You MUST Know - DigitalOcean
Collections are used in every programming language and when Java arrived, it also came with few Collection classes – Vector, Stack, Hashtable, ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Interesting. With #1806 the registry plugin will be promoted to core, so this feature will be built-in. It would be a good idea to add these instruction on how to create a custom reusable collection to a guide explaining the whole process.
If anyone else stumbles upon this, here’s the correct way to register a custom collection when using the registry plugin:
After this bootstrap everything runs as expected currently (except that Collection.fetched event isn’t fired on a relation call as I would have expected - but Collection.fetching does).