Ejemplo n.º 1
0
 /**
  * Returns true if at least one of the local columns of $fk is not already covered by another
  * foreignKey in our collection (getCrossForeignKeys)
  *
  * E.g.
  *
  * table (local primary keys -> foreignKey):
  *
  *   pk1  -> FK1
  *   pk2
  *      \
  *        -> FK2
  *      /
  *   pk3  -> FK3
  *      \
  *        -> FK4
  *      /
  *   pk4
  *
  *  => FK1(pk1), FK2(pk2, pk3), FK3(pk3), FK4(pk3, pk4).
  *
  *  isAtLeastOneLocalPrimaryKeyNotCovered(FK1) where none fks in our collection: true
  *  isAtLeastOneLocalPrimaryKeyNotCovered(FK2) where FK1 is in our collection: true
  *  isAtLeastOneLocalPrimaryKeyNotCovered(FK3) where FK1,FK2 is in our collection: false
  *  isAtLeastOneLocalPrimaryKeyNotCovered(FK4) where FK1,FK2 is in our collection: true
  *
  * @param  ForeignKey $fk
  * @return bool
  */
 public function isAtLeastOneLocalPrimaryKeyNotCovered(ForeignKey $fk)
 {
     $primaryKeys = $fk->getLocalPrimaryKeys();
     foreach ($primaryKeys as $primaryKey) {
         $covered = false;
         foreach ($this->getCrossForeignKeys() as $crossFK) {
             if ($crossFK->hasLocalColumn($primaryKey)) {
                 $covered = true;
                 break;
             }
         }
         //at least one is not covered, so return true
         if (!$covered) {
             return true;
         }
     }
     return false;
 }