balderdashy / balderdashy/sails

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

Open
#4,667 17 comments 1 reaction 0 assignees View on GitHub
orm v2.x
Dominant language
JavaScript
Stars
22.8k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

**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\' ] }

Contributor guide

Open the contributing guide

Research direction

Start with the Pet.find().populate('petType', { select: ['name'] }) call and the Waterline error shown in the issue. Trace how singular model associations handle populate subcriteria, then verify that selecting the PetType name no longer produces the ambiguity error and returns the requested field.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
backend, database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.