Skip to content

.populate('petType', {select: ['species']}) ("Ambiguous usage with singular model association") #4667

@german970814

Description

@german970814

Sails version: 1.1.0
Node version: 8.10
NPM version: 5.6.0
DB adapter name: sails-mysql
DB adapter version: 1.0.1
Operating system: Debian GNU/Linux 8 (jessie)


I'm running my project on docker image with *nodev8.10*. I have a model with a single association with another model, example
/*Pet*/
module.exports = {
    attributes: {
      name: { type: 'string' },
      petType: {
        model: 'pettype'
      }
    }
}

/*PetType*/
module.exports = {
    attributes: {
      name: { type: 'string' },
    }
}

Then I try to populate my Pet model with specific PetType fields, like this:

await Pet.find().populate('petType', { select: ['name'] });

And I get the following error:

Could not populate petType because of ambiguous usage. This is a singular ("model") association, which means it never refers to more than one associated record. So passing in subcriteria (i.e. as the second argument to .populate()) is not supported for this association, since it generally wouldn't make any sense. But that's the trouble-- it looks like some sort of a subcriteria (or something) was provided!\n(Note that subcriterias consisting ONLY of omit or select are a special case that does make sense. This usage will be supported in a future version of Waterline.)\n\nHere's what was passed in:\n{ select: [ 'name' ] }

Metadata

Metadata

Assignees

No one assigned

    Labels

    ormRelated to models, datastores, orm config, Waterline, sails-hook-orm, etc.v2.xThis is related to a feature or change (tentatively) destined for Sails v2.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions