node-orm2
node-orm2 copied to clipboard
Exclude associations from autoFetch
autoFetch
is a really cool feature. But it can prove to be unpractical when returning far too much data, that is actually not needed.
Imagine having users and messages grouped into conversations with other participating users. Writing
user.getConversations({ autoFetch: true }, function (err, conversations) {
// conersation.participants
// conversation.messages
});
is really convenient, but it will return all messages for all conversations, even when they are not needed to display a overview of available conversations.
I would like to propose the following syntax:
user.getConversations({ autoFetch: [ 'participants' ] }, function (err, conversations) {
// conversation.participants
});
The autoFetch
will only include the associations given. If autoFetch
is set to true
, then just fetch all associations. If it is an array, only fetch the ones specified.
This is a great idea, will try to do it when I have some time.
@dresende I also concur that this is a great idea. Has there been any progress on this enhancement?
+1
+1
+1