node-orm2 icon indicating copy to clipboard operation
node-orm2 copied to clipboard

Exclude associations from autoFetch

Open ptnplanet opened this issue 11 years ago • 5 comments

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.

ptnplanet avatar Sep 23 '13 20:09 ptnplanet

This is a great idea, will try to do it when I have some time.

dresende avatar Sep 24 '13 18:09 dresende

@dresende I also concur that this is a great idea. Has there been any progress on this enhancement?

bvallelunga avatar Mar 31 '14 07:03 bvallelunga

+1

twk-b avatar Sep 22 '14 17:09 twk-b

+1

tomzilla avatar Oct 30 '15 00:10 tomzilla

+1

lawrencebensaid avatar Jun 05 '21 20:06 lawrencebensaid