Skip to content

Commit 17a4110

Browse files
committed
Merge branch '3.x' into develop
2 parents b26af0f + c7c9a76 commit 17a4110

File tree

5 files changed

+22
-14
lines changed

5 files changed

+22
-14
lines changed

src/Database/Concerns/HasReplication.php

+18
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,22 @@ public function newReplicationInstance($attributes)
4949

5050
return $instance;
5151
}
52+
53+
/**
54+
* isRelationReplicable determines whether the specified relation should be replicated
55+
*/
56+
public function isRelationReplicable(string $name): bool
57+
{
58+
$relationType = $this->getRelationType($name);
59+
if ($relationType === 'morphTo') {
60+
return false;
61+
}
62+
63+
$definition = $this->getRelationDefinition($name);
64+
if (!array_key_exists('replicate', $definition)) {
65+
return true;
66+
}
67+
68+
return (bool) $definition['replicate'];
69+
}
5270
}

src/Database/Relations/AttachOne.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function __construct(Builder $query, Model $parent, $type, $id, $isPublic
4040
public function setSimpleValue($value)
4141
{
4242
if (is_array($value)) {
43-
$value = reset($value);
43+
$value = current($value);
4444
}
4545

4646
// Nulling the relationship

src/Database/Relations/HasOne.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function __construct(Builder $query, Model $parent, $foreignKey, $localKe
3434
public function setSimpleValue($value)
3535
{
3636
if (is_array($value)) {
37-
return;
37+
$value = current($value);
3838
}
3939

4040
// Nulling the relationship

src/Database/Relations/MorphOne.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function __construct(Builder $query, Model $parent, $type, $id, $localKey
3434
public function setSimpleValue($value)
3535
{
3636
if (is_array($value)) {
37-
return;
37+
$value = current($value);
3838
}
3939

4040
// Nulling the relationship

src/Database/Replicator.php

+1-11
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,6 @@ protected function replicateRelationInternal($relationObject, $models)
141141
*/
142142
protected function isRelationReplicable(string $name): bool
143143
{
144-
$relationType = $this->model->getRelationType($name);
145-
if ($relationType === 'morphTo') {
146-
return false;
147-
}
148-
149144
// Relation is shared via propagation
150145
if (
151146
!$this->isDuplicating &&
@@ -155,12 +150,7 @@ protected function isRelationReplicable(string $name): bool
155150
return false;
156151
}
157152

158-
$definition = $this->model->getRelationDefinition($name);
159-
if (!array_key_exists('replicate', $definition)) {
160-
return true;
161-
}
162-
163-
return (bool) $definition['replicate'];
153+
return $this->model->isRelationReplicable($name);
164154
}
165155

166156
/**

0 commit comments

Comments
 (0)