Atlantis-Software / sails-hook-orm-offshore

Implements support for Offshore ORM in Sails.
https://github.com/Atlantis-Software/Offshore
8 stars 1 forks source link

Taking few params not workning when populate #4

Closed bonanzakrak closed 8 years ago

bonanzakrak commented 8 years ago

First of all I'm using MongoDB driver. For example we have 2 Models. User which is not important in this case, and Test:

attributes: {
    USER: {
        model: 'User'
    },
    F1: {
        type: 'string'
    },
    F2: {
        type: 'string'
    },
    F3: {
        type: 'string'
    },
}

and now we want to query that:

this.find().populate('USER').exec(callback);

And this works perfectly fine. Unless we want to add select param to out find method.

this.find({
    select: ['F1']
}).populate('USER').exec(callback);

This will return all F1, F2and F3. We can remove populate.

this.find({
    select: ['F1']
}).exec(callback);

Without populate it works fine. It returns only F1 as expected.

atiertant commented 8 years ago

@bonanzakrak hi, does this work correctly using waterline? did you tryied using another adapter? could you add a console.log at top of adapter join function to see input?

as you can see here https://github.com/balderdashy/sails-mongo/blob/master/lib/adapter.js#L447 it looks like sails-mongo does not support select with populate...

we'd love writting an offshore-mongo adapter but we don't have time for this now...

bonanzakrak commented 8 years ago

Thats true. sails-mongo is the issue here. Those lines:

if (typeof criteria === 'object') {
    delete criteria.select;
}

I think i know what author had in his mind. Not allow user to join over fields that are not selected. But it is done in a wrong way :/

I need to write it other way now. Thanks for your help.