Skip to content

Commit fd4434f

Browse files
committed
Update HasMany.php
Conditional checking if can set pass on attributes
1 parent b90723a commit fd4434f

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/Support/Relations/HasMany.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,9 @@ public function last()
160160

161161
public function getRelationFromApi()
162162
{
163-
$this->relation = $this->newRelation($this->updateFields([]))->setPassOnAttributes($this->getUpdateKeys())->all();
163+
if(method_exists($relation = $this->newRelation($this->updateFields([])), 'setPassOnAttributes')) {
164+
$this->relation = $relation->setPassOnAttributes($this->getUpdateKeys())->all();
165+
}
164166
if($this->hasUpdateFields()){
165167
foreach($this->relation as $object){
166168
$this->updateFields($object);
@@ -201,7 +203,10 @@ public function __call($method, $parameters)
201203
if($this->relation->count() > 0 && method_exists($this->relation, $method)){
202204
return $this->forwardCallTo($this->relation, $method, $parameters);
203205
} else {
204-
$relation = $this->newRelation($this->updateFields([]))->setPassOnAttributes($this->getUpdateKeys());
206+
$relation = $this->newRelation($this->updateFields([]));
207+
if(method_exists($relation, 'setPassOnAttributes')){
208+
$relation->setPassOnAttributes($this->getUpdateKeys());
209+
}
205210
return $this->forwardCallTo($relation, $method, $parameters);
206211
}
207212
}

0 commit comments

Comments
 (0)