-
Notifications
You must be signed in to change notification settings - Fork 362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Model include doesn't handle 'hasMany through' correctly #85
Comments
We should add an integration test to loopback for this: setup models with "hasMany through", perform a REST request with "include" field and verify that the related objects were included. |
I started to write the unit-test and it seems those two pull requests did not fix the issue fully. Consider the following setup: var product = app.model(
'product',
{ properties: { id: 'string', name: 'string' }, dataSource: 'db' }
);
var category = app.model(
'category',
{ properties: { id: 'string', name: 'string' }, dataSource: 'db' }
);
product.hasAndBelongsToMany(category);
category.hasAndBelongsToMany(product);
category.create({ name: 'CAT-NAME' }, function(err, cat) {
// assume cat has id "CAT-ID"
cat.products.create({ name: 'PROD-NAME' }, function(err, prod) {
// assume prod has id "PROD-ID"
// done/next
});
}); This request works as expected:
These two do not work though:
@raymondfeng is that expected? |
The syntax for the include option is wrong. It should be something like: ?filter[where][id]=CAT-ID&filter[include]=products |
Thanks, find/findOne work now. What's the correct URL for findById with include? Neither of these work:
|
I fixed my test for find by categoryId and realised it does not work.
|
Summary: ✅ ❌ ❌ |
At the moment, LoopBack supports these two use-cases:
I have opened two follow-up issues #93 and #94 to implement the other two uses cases mentioned above. @raymondfeng I suppose we can close the issue once the new version of loopback-datasource-juggler is released. |
https://groups.google.com/forum/#!topic/loopbackjs/PWB4naSgYZg
The text was updated successfully, but these errors were encountered: