@@ 804-826 (lines=23) @@ | ||
801 | /** |
|
802 | * @inheritDoc |
|
803 | */ |
|
804 | public function hasForeignKey($tableName, $columns, $constraint = null) |
|
805 | { |
|
806 | if (is_string($columns)) { |
|
807 | $columns = [$columns]; // str to array |
|
808 | } |
|
809 | $foreignKeys = $this->getForeignKeys($tableName); |
|
810 | if ($constraint) { |
|
811 | if (isset($foreignKeys[$constraint])) { |
|
812 | return !empty($foreignKeys[$constraint]); |
|
813 | } |
|
814 | ||
815 | return false; |
|
816 | } |
|
817 | ||
818 | foreach ($foreignKeys as $key) { |
|
819 | $a = array_diff($columns, $key['columns']); |
|
820 | if (empty($a)) { |
|
821 | return true; |
|
822 | } |
|
823 | } |
|
824 | ||
825 | return false; |
|
826 | } |
|
827 | ||
828 | /** |
|
829 | * Get an array of foreign keys from a particular table. |
@@ 896-918 (lines=23) @@ | ||
893 | /** |
|
894 | * @inheritDoc |
|
895 | */ |
|
896 | public function hasForeignKey($tableName, $columns, $constraint = null) |
|
897 | { |
|
898 | if (is_string($columns)) { |
|
899 | $columns = [$columns]; // str to array |
|
900 | } |
|
901 | $foreignKeys = $this->getForeignKeys($tableName); |
|
902 | if ($constraint) { |
|
903 | if (isset($foreignKeys[$constraint])) { |
|
904 | return !empty($foreignKeys[$constraint]); |
|
905 | } |
|
906 | ||
907 | return false; |
|
908 | } else { |
|
909 | foreach ($foreignKeys as $key) { |
|
910 | $a = array_diff($columns, $key['columns']); |
|
911 | if (empty($a)) { |
|
912 | return true; |
|
913 | } |
|
914 | } |
|
915 | ||
916 | return false; |
|
917 | } |
|
918 | } |
|
919 | ||
920 | /** |
|
921 | * Get an array of foreign keys from a particular table. |