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

Created on 11 Mar 2019  路  13Comments  路  Source: balderdashy/sails

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.)nnHere's what was passed in:n{ select: [ 'name' ] }

helpful info or workaround orm v2.x

Most helpful comment

@axul the ability to use omit and select with .populate() would be a good candidate for a future version of Sails/Waterline, but it is not supported in the current version. Currently, .populate() doesn't take additional subcriteria (hopefully @mikermcneil's change to the error message wording will help clarify this going forward).

All 13 comments

Hi @german970814! It looks like you missed a step or two when you created your issue. Please edit your comment (use the pencil icon at the top-right corner of the comment box) and fix the following:

  • Verify "I am experiencing a concrete technical issue (aka a bug) with Sails (ideas and feature proposals should follow the guide for proposing features and enhancements (http://bit.ly/sails-feature-guide), which involves making a pull request). If you're not 100% certain whether it's a bug or not, that's okay--you may continue. The worst that can happen is that the issue will be closed and we'll point you in the right direction."
  • Verify "I am not asking a question about how to use Sails or about whether or not Sails has a certain feature (please refer to the documentation(http://sailsjs.com), or post on http://stackoverflow.com, our Google Group (http://bit.ly/sails-google-group) or our live chat (https://gitter.im/balderdashy/sails)."
  • Verify "I have already searched for related issues, and found none open (if you found a related _closed_ issue, please link to it in your post)."
  • Verify "My issue title is concise, on-topic and polite ("jst.js being removed from layout.ejs on lift" is good; "templates dont work" or "why is sails dumb" are not so good)."
  • Verify "I have tried all the following (if relevant) and my issue remains:"
  • Verify "I can provide steps to reproduce this issue that others can follow."

As soon as those items are rectified, post a new comment (e.g. “Ok, fixed!”) below and we'll take a look. Thanks!

*If you feel this message is in error, or you want to debate the merits of my existence (sniffle), please contact [email protected]

Ok, fixed!

@german970814 Thanks for posting, we'll take a look as soon as possible.


For help with questions about Sails, click here. If you’re interested in hiring @sailsbot and her minions in Austin, click here.

@abhisheksoni27 as you can see from the error message, adding subcriteria to .populate() isn't supported for singular associations (although omit and select will likely be supported in a _future_ version of waterline).

Since multiple people have made issues asking about that error, Mike just went ahead and updated that error message, since the phrase "ambiguous usage" might have been a bit confusing: https://github.com/balderdashy/waterline/commit/3326984f0355f6d568f61920f0c11bf51e0faa4a

I'm having the same issue and is a really frustrating problem having this arbitrary limitation

@axul the ability to use omit and select with .populate() would be a good candidate for a future version of Sails/Waterline, but it is not supported in the current version. Currently, .populate() doesn't take additional subcriteria (hopefully @mikermcneil's change to the error message wording will help clarify this going forward).

Ok, fixed!

How you got fixed this problem .I still couldn't get cleared with this .I'm seeking for a proper solution.

@vasandhan Ah, what @german970814 meant by "fixed" was that he'd updated his original post with additional info requested by sailsbot (which is great, thanks btw). Sorry for the confusion.

@rachaelshaw 's last post here sums up the current state for this one. Hope this is helpful 馃憤

will this support in v 0.12 @rachaelshaw @johnabrams7

When will be the next version update? Waiting for the update... : )

Hi @rachaelshaw , I am using sails version 1.2.3. i have some of the issues , where i need to get a clear vision of that.
1. How to use Nested Populate
2. How to use subcriteria in populate (for example : .populate('something',{select:[]}))
3. Is Attribute Declaration is necessary in Models for API's
4. How to work with createdAt and updatedAt .

@vasandhan Thats a lot of questions, some of which are answered in the documentation.

There is always https://sailsjs.com/faq#?are-there-professional-support-options if you would like to get more support, but GitHub issues are primarily meant for bugs.

Was this page helpful?
0 / 5 - 0 ratings