2017-06-15 3 views
0

Hello,
I have an issue with saving data in my database, I can’t find the problem. The QueryBuilder for And-, Or- and OrAnd-Select are the same. . I wrote the QueryBuilder in code consecutively for And-select , Or-select and OrAnd-Select in this exact order. Saving data in NosqlDb works only for And- and OR-select .baqend、データベース

But OrAnd-select fails to save. In the picture shown, you can see that the data in database doesn’t save. Data in database User_DataDb saves successfully. I would appreciate any help!

Thank you in advance.

enter image description here

I get this error:

EXCEPTION: Uncaught (in promise): Error: Current operation has not been finished. 
[email protected]://localhost:3000/main.bundle.js:21238:31 [angular] 
[email protected]://localhost:3000/main.bundle.js:11260:12 [angular] 
[email protected]://localhost:3000/main.bundle.js:11097:12 [angular] 
[email protected]://localhost:3000/main.bundle.js:12956:14 [angular] 
ac_main</NoSqlComponent.prototype.submit/promise</</<@http://localhost:3000/main.bundle.js:29457:21 [angular] 
[email protected]://localhost:3000/vendor.dll.js:30326:28 [angular] 
polyfills_lib</</</[email protected]://localhost:3000/polyfills.dll.js:4133:24 [angular => angular] 
scheduleResolveOrReject/<@http://localhost:3000/polyfills.dll.js:4720:52 [angular] 
[email protected]://localhost:3000/vendor.dll.js:30317:28 [angular] 
polyfills_lib</</</[email protected]://localhost:3000/polyfills.dll.js:4373:17 [angular] 
polyfills_lib</</</[email protected]://localhost:3000/polyfills.dll.js:4173:28 [<root> => angular] 
[email protected]://localhost:3000/polyfills.dll.js:4553:25 [<root>] 
ZoneTask/[email protected]://localhost:3000/polyfills.dll.js:4431:25 [<root>] 

My code

/////////////// 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 }); 
            }); 
          }); 
        }); 
      }); 
     });  

答えて

0

でセーブデータとの問題は、私がここにあなたの問題はあなたがオブジェクトを使用すると、同時に保存しているWICH変更しようとしていること、だと思います。 同じオブジェクトを一度に1回のみ変更して保存するようにしてください。また

、あなたはすでにロードされたオブジェクトをロードしないでください。

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(); 
     }); 
    }); 
関連する問題