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)
/*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
petTypebecause 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 ofomitorselectare 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' ] }
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:
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.
Most helpful comment
@axul the ability to use
omitandselectwith.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).