Esempio n. 1
0
 protected function deleteBridge(DB $aDB, Association $aAssociation, Model $aFromModel, Model $aToModel)
 {
     $aStatementFactory = $aAssociation->fromPrototype()->statementFactory();
     $aDeleteForBridge = $aStatementFactory->createDelete($aAssociation->bridgeTableName());
     $aDeleteForBridge->criteria()->where()->add($this->makeRestrictionForAssocotion($aFromModel, $aAssociation->fromKeys(), null, $aAssociation->toBridgeKeys(), $aStatementFactory));
     $aDB->execute($aDeleteForBridge);
 }
Esempio n. 2
0
 protected function buildBridge(DB $aDB, Association $aAssociation, Model $aFromModel, Model $aToModel)
 {
     $aFromPrototype = $aAssociation->fromPrototype();
     $aSelect = new Select($aAssociation->bridgeTableName());
     $aRestraction = $aSelect->criteria()->where();
     $this->makeResrictionForAsscotion($aRestraction, $aFromPrototype->path(), $aAssociation->fromKeys(), null, $aAssociation->toBridgeKeys());
     $this->makeResrictionForAsscotion($aRestraction, $aAssociation->toPrototype()->path(), $aAssociation->toKeys(), null, $aAssociation->fromBridgeKeys());
     // 检查对应的桥接表记录是否存在
     if (!$aDB->queryCount($aSelect)) {
         $aInsertForBridge = $aStatementFactory->createInsert($aAssociation->bridgeTableName());
         // from table key vale
         $this->setValue($aInsertForBridge, $aAssociation->toBridgeKeys(), $aAssociation->fromKeys(), $aFromModel);
         // to table key vale
         $this->setValue($aInsertForBridge, $aAssociation->fromBridgeKeys(), $aAssociation->toKeys(), $aToModel);
         $aDB->execute($aInsertForBridge);
     }
 }