Performing a collection query, with where conditions, and including relations
See original GitHub issueHey there,
I have two tables, activity_group
and roundtable_user
. activity_group
joins to roundtable_user
on activity_group.performer_id = roundtable_user.id
and the models/collections look like:
var ActivityGroup = bookshelf.Model.extend({
tableName: 'activity_group',
performer: function () {
return this.belongsTo(RoundtableUser)
}
})
var RoundtableUser = bookshelf.Model.extend({
tableName: 'roundtable_user'
}
var ActivityGroupCollection = bookshelf.Collection.extend({
model: ActivityGroup
})
I want to basically do a query from activity_group
where (some filters here) and then including the performer
relation. In other words, here’s what I want to say:
ActivityGroupCollection
.fetch({withRelated: ['performer']})
.where({performer_id: ..., ... })
This way, each ActivityGroup
has performer()
filled in. Obviously, though, I can’t write this. I looked through the code and the docs but I couldn’t figure out how to do this. Can you help?
Issue Analytics
- State:
- Created 10 years ago
- Comments:14 (7 by maintainers)
Top Results From Across the Web
Create a query based on multiple tables
Build a select query by using tables with a many-to-many relationship · On the Create tab, in the Queries group, click Query Design....
Read more >Perform simple and compound queries in Cloud Firestore
Cloud Firestore provides powerful query functionality for specifying which documents you want to retrieve from a collection or collection group.
Read more >Relation queries (Concepts)
Prisma Client provides convenient queries for working with relations, such as a fluent API, nested writes (transactions), nested reads and relation filters.
Read more >Query Documents — MongoDB Manual
MongoDB Manual. How do I query documents, query top level fields, perform equality match, query with query operators, specify compound query conditions.
Read more >MongoDB Join Two Collections Simplified
We can join documents on collections in MongoDB by using the $lookup (Aggregation) function.
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
What if you wanted the ‘withRelated’ to not be a separate query executed, but instead be a join ?
ie. get the activity group with the performer where the performer name is ‘steve’ ?
Hello,
how can I write down a bookshelf query same as mysql’s “between … and” query
thanks