@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | $ownerKeys = $this->getOwnerKeys(); |
| 30 | 30 | $foreignKeys = $this->getForeignKeys(); |
| 31 | 31 | |
| 32 | - if(count($ownerKeys)!=count($foreignKeys)) |
|
| 32 | + if (count($ownerKeys) != count($foreignKeys)) |
|
| 33 | 33 | throw new WrongRelationConfigurationException(); |
| 34 | 34 | |
| 35 | 35 | foreach ($ownerKeys as $keyIndex => $key) |
@@ -50,21 +50,21 @@ discard block |
||
| 50 | 50 | // We'll grab the primary key name of the related models since it could be set to |
| 51 | 51 | // a non-standard name and not "id". We will then construct the constraint for |
| 52 | 52 | // our eagerly loading query so it returns the proper models from execution. |
| 53 | - (new CompositeKeyScope(array_map(function($keyName){ |
|
| 53 | + (new CompositeKeyScope(array_map(function($keyName) { |
|
| 54 | 54 | return $this->related->getTable().'.'.$keyName; |
| 55 | - }, $ownerKeys), $this->getEagerModelKeys($models), false, method_exists($this->related,'getBinaryColumns') ? $this->related->getBinaryColumns() : []))->apply($this->query); |
|
| 55 | + }, $ownerKeys), $this->getEagerModelKeys($models), false, method_exists($this->related, 'getBinaryColumns') ? $this->related->getBinaryColumns() : []))->apply($this->query); |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | public function getOwnerKeys() |
| 59 | 59 | { |
| 60 | - if(method_exists($this->parent, 'hasCompositeIndex') && $this->parent->hasCompositeIndex() && !is_array($this->ownerKey) && strpos($this->ownerKey,$this->magicKeyDelimiter) !== false) |
|
| 60 | + if (method_exists($this->parent, 'hasCompositeIndex') && $this->parent->hasCompositeIndex() && !is_array($this->ownerKey) && strpos($this->ownerKey, $this->magicKeyDelimiter) !== false) |
|
| 61 | 61 | $this->ownerKey = explode($this->magicKeyDelimiter, $this->ownerKey); |
| 62 | 62 | return !is_array($this->ownerKey) ? [$this->ownerKey] : $this->ownerKey; |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | public function getForeignKeys() |
| 66 | 66 | { |
| 67 | - if(method_exists($this->related, 'hasCompositeIndex') && $this->related->hasCompositeIndex() && !is_array($this->foreignKey) && strpos($this->foreignKey,$this->magicKeyDelimiter) !== false) |
|
| 67 | + if (method_exists($this->related, 'hasCompositeIndex') && $this->related->hasCompositeIndex() && !is_array($this->foreignKey) && strpos($this->foreignKey, $this->magicKeyDelimiter) !== false) |
|
| 68 | 68 | $this->foreignKey = explode($this->magicKeyDelimiter, $this->foreignKey); |
| 69 | 69 | return !is_array($this->foreignKey) ? [$this->foreignKey] : $this->foreignKey; |
| 70 | 70 | } |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | $keys[] = $compositeKey; |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - if(count($foreignKeys) == 1) { |
|
| 98 | + if (count($foreignKeys) == 1) { |
|
| 99 | 99 | // If there are no keys that were not null we will just return an array with null |
| 100 | 100 | // so this query wont fail plus returns zero results, which should be what the |
| 101 | 101 | // developer expects to happen in this situation. Otherwise we'll sort them. |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | $dictionary = []; |
| 132 | 132 | |
| 133 | 133 | foreach ($results as $result) { |
| 134 | - $dictionary[implode($this->magicKeyDelimiter,array_map(function($owner) use ($result) { |
|
| 134 | + $dictionary[implode($this->magicKeyDelimiter, array_map(function($owner) use ($result) { |
|
| 135 | 135 | return $result->getAttribute($owner); |
| 136 | 136 | }, $ownerKeys))] = $result; |
| 137 | 137 | } |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | // and match back onto their children using these keys of the dictionary and |
| 141 | 141 | // the primary key of the children to map them onto the correct instances. |
| 142 | 142 | foreach ($models as $model) { |
| 143 | - $foreignKey = implode($this->magicKeyDelimiter,array_map(function($foreign) use ($model) { |
|
| 143 | + $foreignKey = implode($this->magicKeyDelimiter, array_map(function($foreign) use ($model) { |
|
| 144 | 144 | return $model->{$foreign}; |
| 145 | 145 | }, $foreignKeys)); |
| 146 | 146 | if (isset($dictionary[$foreignKey])) { |
@@ -29,11 +29,13 @@ discard block |
||
| 29 | 29 | $ownerKeys = $this->getOwnerKeys(); |
| 30 | 30 | $foreignKeys = $this->getForeignKeys(); |
| 31 | 31 | |
| 32 | - if(count($ownerKeys)!=count($foreignKeys)) |
|
| 33 | - throw new WrongRelationConfigurationException(); |
|
| 32 | + if(count($ownerKeys)!=count($foreignKeys)) { |
|
| 33 | + throw new WrongRelationConfigurationException(); |
|
| 34 | + } |
|
| 34 | 35 | |
| 35 | - foreach ($ownerKeys as $keyIndex => $key) |
|
| 36 | - $this->query->where($table.'.'.$key, '=', $this->child->{$foreignKeys[$keyIndex]}); |
|
| 36 | + foreach ($ownerKeys as $keyIndex => $key) { |
|
| 37 | + $this->query->where($table.'.'.$key, '=', $this->child->{$foreignKeys[$keyIndex]}); |
|
| 38 | + } |
|
| 37 | 39 | } |
| 38 | 40 | } |
| 39 | 41 | |
@@ -57,15 +59,17 @@ discard block |
||
| 57 | 59 | |
| 58 | 60 | public function getOwnerKeys() |
| 59 | 61 | { |
| 60 | - if(method_exists($this->parent, 'hasCompositeIndex') && $this->parent->hasCompositeIndex() && !is_array($this->ownerKey) && strpos($this->ownerKey,$this->magicKeyDelimiter) !== false) |
|
| 61 | - $this->ownerKey = explode($this->magicKeyDelimiter, $this->ownerKey); |
|
| 62 | + if(method_exists($this->parent, 'hasCompositeIndex') && $this->parent->hasCompositeIndex() && !is_array($this->ownerKey) && strpos($this->ownerKey,$this->magicKeyDelimiter) !== false) { |
|
| 63 | + $this->ownerKey = explode($this->magicKeyDelimiter, $this->ownerKey); |
|
| 64 | + } |
|
| 62 | 65 | return !is_array($this->ownerKey) ? [$this->ownerKey] : $this->ownerKey; |
| 63 | 66 | } |
| 64 | 67 | |
| 65 | 68 | public function getForeignKeys() |
| 66 | 69 | { |
| 67 | - if(method_exists($this->related, 'hasCompositeIndex') && $this->related->hasCompositeIndex() && !is_array($this->foreignKey) && strpos($this->foreignKey,$this->magicKeyDelimiter) !== false) |
|
| 68 | - $this->foreignKey = explode($this->magicKeyDelimiter, $this->foreignKey); |
|
| 70 | + if(method_exists($this->related, 'hasCompositeIndex') && $this->related->hasCompositeIndex() && !is_array($this->foreignKey) && strpos($this->foreignKey,$this->magicKeyDelimiter) !== false) { |
|
| 71 | + $this->foreignKey = explode($this->magicKeyDelimiter, $this->foreignKey); |
|
| 72 | + } |
|
| 69 | 73 | return !is_array($this->foreignKey) ? [$this->foreignKey] : $this->foreignKey; |
| 70 | 74 | } |
| 71 | 75 | |
@@ -106,9 +110,9 @@ discard block |
||
| 106 | 110 | sort($keys); |
| 107 | 111 | |
| 108 | 112 | return array_values(array_unique($keys)); |
| 113 | + } else { |
|
| 114 | + return $keys; |
|
| 109 | 115 | } |
| 110 | - else |
|
| 111 | - return $keys; |
|
| 112 | 116 | } |
| 113 | 117 | |
| 114 | 118 | /** |