| @@ 736-756 (lines=21) @@ | ||
| 733 | /** |
|
| 734 | * {@inheritdoc} |
|
| 735 | */ |
|
| 736 | public function hasForeignKey($tableName, $columns, $constraint = null) |
|
| 737 | { |
|
| 738 | if (is_string($columns)) { |
|
| 739 | $columns = [$columns]; // str to array |
|
| 740 | } |
|
| 741 | $foreignKeys = $this->getForeignKeys($tableName); |
|
| 742 | if ($constraint) { |
|
| 743 | if (isset($foreignKeys[$constraint])) { |
|
| 744 | return !empty($foreignKeys[$constraint]); |
|
| 745 | } |
|
| 746 | return false; |
|
| 747 | } else { |
|
| 748 | foreach ($foreignKeys as $key) { |
|
| 749 | $a = array_diff($columns, $key['columns']); |
|
| 750 | if (empty($a)) { |
|
| 751 | return true; |
|
| 752 | } |
|
| 753 | } |
|
| 754 | return false; |
|
| 755 | } |
|
| 756 | } |
|
| 757 | ||
| 758 | /** |
|
| 759 | * Get an array of foreign keys from a particular table. |
|
| @@ 583-602 (lines=20) @@ | ||
| 580 | /** |
|
| 581 | * {@inheritdoc} |
|
| 582 | */ |
|
| 583 | public function hasForeignKey($tableName, $columns, $constraint = null) |
|
| 584 | { |
|
| 585 | if (is_string($columns)) { |
|
| 586 | $columns = [$columns]; // str to array |
|
| 587 | } |
|
| 588 | $foreignKeys = $this->getForeignKeys($tableName); |
|
| 589 | if ($constraint) { |
|
| 590 | if (isset($foreignKeys[$constraint])) { |
|
| 591 | return !empty($foreignKeys[$constraint]); |
|
| 592 | } |
|
| 593 | return false; |
|
| 594 | } else { |
|
| 595 | foreach ($foreignKeys as $key) { |
|
| 596 | if ($columns == $key['columns']) { |
|
| 597 | return true; |
|
| 598 | } |
|
| 599 | } |
|
| 600 | return false; |
|
| 601 | } |
|
| 602 | } |
|
| 603 | ||
| 604 | /** |
|
| 605 | * Get an array of foreign keys from a particular table. |
|
| @@ 611-631 (lines=21) @@ | ||
| 608 | /** |
|
| 609 | * {@inheritdoc} |
|
| 610 | */ |
|
| 611 | public function hasForeignKey($tableName, $columns, $constraint = null) |
|
| 612 | { |
|
| 613 | if (is_string($columns)) { |
|
| 614 | $columns = [$columns]; // str to array |
|
| 615 | } |
|
| 616 | $foreignKeys = $this->getForeignKeys($tableName); |
|
| 617 | if ($constraint) { |
|
| 618 | if (isset($foreignKeys[$constraint])) { |
|
| 619 | return !empty($foreignKeys[$constraint]); |
|
| 620 | } |
|
| 621 | return false; |
|
| 622 | } else { |
|
| 623 | foreach ($foreignKeys as $key) { |
|
| 624 | $a = array_diff($columns, $key['columns']); |
|
| 625 | if (empty($a)) { |
|
| 626 | return true; |
|
| 627 | } |
|
| 628 | } |
|
| 629 | return false; |
|
| 630 | } |
|
| 631 | } |
|
| 632 | ||
| 633 | /** |
|
| 634 | * Get an array of foreign keys from a particular table. |
|