Пример #1
0
 public function createModifyManyToMany(Association\ManyToMany $association, $primaryValue, array $refKeys, $action = self::ASSOC_ADD)
 {
     if ($association->getJoinKey() !== "uzivatelske-vazby") {
         throw new \Exception("Only custom relations can be modified!");
     }
     if ($action === self::ASSOC_ADD) {
         $values = [];
         foreach ($refKeys as $refkey) {
             $values[] = ["id" => $primaryValue, "uzivatelske-vazby" => ["uzivatelska-vazba" => ["evidenceType" => $association->getTargetResource(), "object" => $refkey, "vazbaTyp" => $association->getJoinResource()]]];
         }
         $query = $this->createInsert($association->getSourceResource(), $values);
     } elseif ($action === self::ASSOC_REMOVE) {
         throw new \Exception("Custom relation delete not implemented!");
     }
     return $query;
 }
Пример #2
0
 public function createModifyManyToMany(Association\ManyToMany $association, $primaryValue, array $refKeys, $action = self::ASSOC_ADD)
 {
     if ($action === self::ASSOC_ADD) {
         $fluent = $this->connection->insert($association->getJoinResource(), [$association->getJoinKey() => array_fill(0, count($refKeys), $primaryValue), $association->getReferencingKey() => $refKeys]);
     } else {
         $fluent = $this->connection->delete($association->getJoinResource())->where("%n = %s", $association->getJoinKey(), $primaryValue)->and("%n IN %l", $association->getReferencingKey(), $refKeys);
     }
     $query = new Query($fluent);
     $query->resultCallback = function (Query $query) {
         return $query->fluent->execute();
     };
     return $query;
 }