问题
I have some strange behavior after moving from RedHat linux to SUSE on AWS.
Everything was working fine, before.
Here is my relations:
Category:
{
"name": "Category",
"plural": "categories",
"base": "PersistedModel",
"relations": {
...
"professions": {
"type": "hasMany",
"model": "Profession",
"foreignKey": ""
}
}
}
Profession:
{
"name": "Profession",
"plural": "professions",
"base": "PersistedModel",
"relations": {
...
"category": {
"type": "belongsTo",
"model": "Category",
"foreignKey": ""
}
}
}
The problem is that when I update an existing profession with:
{
"categoryId" : "..."
}
It doesn't work when I request /api/categories/{id}/professions
But /api/profession/{id}/category works fine.
Also if I create new Profession like:
{
"name" : "TEST",
"categoryId" : "..."
}
It works fine both ways.
Category.professions.create({ name: "TEST2" }); Works fine as well.
I was using RedHat linux on AWS. Now I am using SUSE linux on AWS.
Mongo db version : db version v3.0.7
EDIT:
node --version
v5.4.1
npm --version
3.3.12
npm list loopback
`-- loopback@2.26.2
EDIT:
I tried to update it from /explorer panel and code.
in code (angular) I do this:
Profession.prototype$updateAttributes(
{
id: toAdd[i]
},
{
categoryId: catId
});
And as I said, all the code works on test server running RDHE. I will check mongo logs, but I installed the same mongo version and using same mongo.config
回答1:
Okey... so the problem was one or both of these modules:
"loopback-connector-mongodb": "^1.13.0"
"loopback-datasource-juggler": "^2.39.0"
Since the version number is written as ^#.#.# it means higher but compatible. But one of them wasn't working: https://github.com/strongloop/loopback/issues/274
This caused all the problems.
Simple solution:
"loopback-connector-mongodb": "1.13.0"
"loopback-datasource-juggler": "2.39.0"
I just installed the versions which i know that works.
来源:https://stackoverflow.com/questions/35338292/loopback-hasmany-relation-doesnt-work-on-mongodb