Angular baqend,在数据库中保存数据时出现问题
你好,Angular baqend,在数据库中保存数据时出现问题,angular,typescript,baqend,Angular,Typescript,Baqend,你好, 我在数据库中保存数据时遇到问题,我找不到 这个问题。用于和-,或-和或的查询生成器,然后选择 同样的。我在代码中连续为编写了QueryBuilder,然后依次选择、或选择和或选择。 在NosqlDb中保存数据仅适用于和-And或select 但或选择无法保存。如图所示, 您可以看到数据库中的数据没有保存。数据库中的数据 User\u DataDb成功保存。 我将感谢任何帮助 先谢谢你 我得到这个错误: 我认为您的问题是,您尝试修改一个对象,同时保存该对象。 您应该确保一次只修改和保存同
我在数据库中保存数据时遇到问题,我找不到 这个问题。用于
和-,或-和或的查询生成器
,然后选择
同样的。我在代码中连续为编写了QueryBuilder
,然后依次选择、或选择和或选择。
在NosqlDb
中保存数据仅适用于和-And或select
但或选择无法保存。如图所示,
您可以看到数据库中的数据没有保存。数据库中的数据
User\u DataDb
成功保存。
我将感谢任何帮助
先谢谢你
我得到这个错误:
我认为您的问题是,您尝试修改一个对象,同时保存该对象。
您应该确保一次只修改和保存同一对象一次
此外,不应加载已加载的对象:
var promiseOr = queryBuilderOr.or(techniques, functional, nonFunctional)
.resultList()
.then((nosqlDbOr) => {
console.log(nosqlDbOr);
this.nosqlDbsOr = nosqlDbOr;
console.log("this.nosqlDbsOr ", this.nosqlDbsOr);
this.nosqlDbsOr.forEach((or) => {
//you do not need a db.NoSqlDB.find() here the object is already loaded
if (and.users_or === null) {
and.users_or = new Set();
}
or.users_or.add(db.User.me);
//You are selecting the same object in the different queries multiple times.
//Therfore do not update the objects in each of the resultList() callbacks
return or.update();
});
});
/////////////// queryBuilder for And-Select
var queryBuilderAnd = db.NoSqlDB.find();
var techniques = queryBuilderAnd
.in('techniques', this.arrStrTchn);
var functional = queryBuilderAnd
.in('functional', this.arrStrFn);
var nonFunctional = queryBuilderAnd
.in('nonFunctional', this.arrStrNFn);
var promiseAnd = queryBuilderAnd.and(techniques, functional, nonFunctional)
.resultList()
.then((nosqlDbAnd) => {
console.log(nosqlDbAnd);
this.nosqlDbsAnd = nosqlDbAnd;
console.log("this.nosqlDbsAnd ", this.nosqlDbsAnd);
this.nosqlDbsAnd.forEach(
(and) => {
console.log("and: " + and.id);
db.NoSqlDB.find()
.equal('id', and.id)
.resultList((result) => {
result.forEach((todo) => {
and.select_and = JSON.parse(JSON.stringify(this.andselected));
if (and.users_and === null) {
and.users_and = new Set();
}
and.users_and.add(db.User.me);
return and.update();
});
});
new db.User_DataDb(
{
functional_select: this.functionalCatObj, nonfunctional_select: this.nfunctionalCatObj,
techniques_select: this.techniquesCatObj, functional_unselect: this.functionalUnsCatObj,
nonfunctional_unselect: this.nfunctionalCatObj, techniques_unselect: this.techniquesUnsCatObj,
ref_NosqlDbAnd: [and.id]
}).insert()
.then((todo1) => {
console.log("todo1.id: ", todo1.id);
db.User_DataDb.find()
.where({
'ref_NosqlDbAnd': and.id,
'id': todo1.id
})
.resultList((result) => {
result.forEach(
(todo2) => {
if (todo2.user_and === null) {
todo2.user_and = new Set();
}
todo2.user_and.add(db.User.me);
return todo2.save({ refresh: true });
});
});
});
});
});
/////////////// queryBuilder for OR-Select
var queryBuilderOr = db.NoSqlDB.find();
var techniques = queryBuilderOr
.in('techniques', this.arrStrTchn);
var functional = queryBuilderOr
.in('functional', this.arrStrFn);
var nonFunctional = queryBuilderOr
.in('nonFunctional', this.arrStrNFn);
var promiseOr = queryBuilderOr.or(techniques, functional, nonFunctional)
.resultList()
.then((nosqlDbOr) => {
console.log(nosqlDbOr);
this.nosqlDbsOr = nosqlDbOr;
console.log("this.nosqlDbsOr ", this.nosqlDbsOr);
this.nosqlDbsOr.forEach(
(or) => {
db.NoSqlDB.find()
.equal('id', or.id)
.resultList((result) => {
result.forEach((todo) => {
or.select_or = JSON.parse(JSON.stringify(this.orselected));
if (or.users_or === null) {
or.users_or = new Set();
}
or.users_or.add(db.User.me);
return or.update();
});
});
new db.User_DataDb(
{
functional_select: this.functionalCatObj, nonfunctional_select: this.nfunctionalCatObj,
techniques_select: this.techniquesCatObj, functional_unselect: this.functionalUnsCatObj,
nonfunctional_unselect: this.nfunctionalCatObj, techniques_unselect: this.techniquesUnsCatObj,
ref_NosqlDbOr: [or.id]
}).insert()
.then((todo1) => {
console.log("todo1.id: ", todo1.id);
db.User_DataDb.find()
.where({
'ref_NosqlDbOr': or.id,
'id': todo1.id
})
.resultList((result) => {
result.forEach(
(todo2) => {
if (todo2.user_or === null) {
todo2.user_or = new Set();
}
todo2.user_or.add(db.User.me);
return todo2.save({ refresh: true });
});
});
});
});
});
var promiseOr = queryBuilderOr.or(techniques, functional, nonFunctional)
.resultList()
.then((nosqlDbOr) => {
console.log(nosqlDbOr);
this.nosqlDbsOr = nosqlDbOr;
console.log("this.nosqlDbsOr ", this.nosqlDbsOr);
this.nosqlDbsOr.forEach((or) => {
//you do not need a db.NoSqlDB.find() here the object is already loaded
if (and.users_or === null) {
and.users_or = new Set();
}
or.users_or.add(db.User.me);
//You are selecting the same object in the different queries multiple times.
//Therfore do not update the objects in each of the resultList() callbacks
return or.update();
});
});