dresende / node-orm2

Object Relational Mapping
http://github.com/dresende/node-orm2
MIT License
3.07k stars 376 forks source link

Exclude associations from autoFetch #342

Open ptnplanet opened 11 years ago

ptnplanet commented 11 years ago

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.

dresende commented 11 years ago

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

bvallelunga commented 10 years ago

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

twk-b commented 10 years ago

+1

tomzilla commented 8 years ago

+1

lawrencebensaid commented 3 years ago

+1