| @@ 647-667 (lines=21) @@ | ||
| 644 | /** |
|
| 645 | * {@inheritdoc} |
|
| 646 | */ |
|
| 647 | public function hasForeignKey($tableName, $columns, $constraint = null) |
|
| 648 | { |
|
| 649 | if (is_string($columns)) { |
|
| 650 | $columns = [$columns]; // str to array |
|
| 651 | } |
|
| 652 | $foreignKeys = $this->getForeignKeys($tableName); |
|
| 653 | if ($constraint) { |
|
| 654 | if (isset($foreignKeys[$constraint])) { |
|
| 655 | return !empty($foreignKeys[$constraint]); |
|
| 656 | } |
|
| 657 | ||
| 658 | return false; |
|
| 659 | } else { |
|
| 660 | foreach ($foreignKeys as $key) { |
|
| 661 | $a = array_diff($columns, $key['columns']); |
|
| 662 | if (empty($a)) { |
|
| 663 | return true; |
|
| 664 | } |
|
| 665 | } |
|
| 666 | ||
| 667 | return false; |
|
| 668 | } |
|
| 669 | } |
|
| 670 | ||
| @@ 761-781 (lines=21) @@ | ||
| 758 | /** |
|
| 759 | * {@inheritdoc} |
|
| 760 | */ |
|
| 761 | public function hasForeignKey($tableName, $columns, $constraint = null) |
|
| 762 | { |
|
| 763 | if (is_string($columns)) { |
|
| 764 | $columns = [$columns]; // str to array |
|
| 765 | } |
|
| 766 | $foreignKeys = $this->getForeignKeys($tableName); |
|
| 767 | if ($constraint) { |
|
| 768 | if (isset($foreignKeys[$constraint])) { |
|
| 769 | return !empty($foreignKeys[$constraint]); |
|
| 770 | } |
|
| 771 | ||
| 772 | return false; |
|
| 773 | } else { |
|
| 774 | foreach ($foreignKeys as $key) { |
|
| 775 | $a = array_diff($columns, $key['columns']); |
|
| 776 | if (empty($a)) { |
|
| 777 | return true; |
|
| 778 | } |
|
| 779 | } |
|
| 780 | ||
| 781 | return false; |
|
| 782 | } |
|
| 783 | } |
|
| 784 | ||
| @@ 564-583 (lines=20) @@ | ||
| 561 | /** |
|
| 562 | * {@inheritdoc} |
|
| 563 | */ |
|
| 564 | public function hasForeignKey( $tableName, $columns, $constraint = null ) { |
|
| 565 | if ( is_string( $columns ) ) { |
|
| 566 | $columns = [ $columns ]; // str to array |
|
| 567 | } |
|
| 568 | $foreignKeys = $this->getForeignKeys( $tableName ); |
|
| 569 | if ( $constraint ) { |
|
| 570 | if ( isset( $foreignKeys[ $constraint ] ) ) { |
|
| 571 | return ! empty( $foreignKeys[ $constraint ] ); |
|
| 572 | } |
|
| 573 | ||
| 574 | return false; |
|
| 575 | } else { |
|
| 576 | foreach ( $foreignKeys as $key ) { |
|
| 577 | if ( $columns == $key['columns'] ) { |
|
| 578 | return true; |
|
| 579 | } |
|
| 580 | } |
|
| 581 | ||
| 582 | return false; |
|
| 583 | } |
|
| 584 | } |
|
| 585 | ||
| 586 | /** |
|