postmanlabs / sails-mysql-transactions

sails/waterline ORM with mySQL transaction support
Apache License 2.0
59 stars 20 forks source link

selection not working on one to many on the one side. #25

Closed shamasis closed 8 years ago

shamasis commented 8 years ago

Refers to .populate(assoc, {select: []})

shamasis commented 8 years ago

@mikermcneil - do you have a few minutes to spare on this problem I'm facing?

When doing sequel.find with the following instructions, the select is not honoured for the user instruction.

{ where: null,
  select: [ 'id', 'user', 'requests' ],
  instructions:
   { user:
      { strategy: { strategy: 1, meta: { parentFK: 'user' } },
        instructions:
         [ { parent: 'groups',
             parentKey: 'user',
             child: 'user',
             childKey: 'id',
             select: [ 'id' ],
             reducedSelection: true,
             alias: 'user',
             removeParentKey: true,
             model: true,
             collection: false,
             criteria: { where: {}, select: [ 'id' ] } } ] } } }

I wanted to avoid peeking into WLSequel and hence, trying to see if this can be addressed from outside. The above instruction is a result from .populate of a one-to-many association of group and user. The select you see is being pushed by our variant of .populate in deferred.js.

shamasis commented 8 years ago

@mikermcneil - had to fork wl-sequel. Is this change worth pushing to original wl-sequel? https://github.com/postmanlabs/waterline-sequel/commit/ce232382c803f1dacead0cc0bb796019dc59e25e

Closing it since #28 fixes it.