Skip to content

Commit 3512030

Browse files
committed
Revert "fix BelongsTo relationship"
This reverts commit d793be4.
1 parent 68ddc29 commit 3512030

File tree

1 file changed

+6
-25
lines changed

1 file changed

+6
-25
lines changed

src/SelectTree.php

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -93,38 +93,19 @@ protected function setUp(): void
9393

9494
// Set the component's state with the extracted IDs.
9595
$component->state($state);
96-
97-
return;
98-
}
99-
100-
/** @var BelongsTo $relationship */
101-
if (! $relatedModel = $relationship->getResults()) {
102-
return;
10396
}
104-
105-
$component->state(
106-
$relatedModel->getAttribute(
107-
$relationship->getOwnerKeyName(),
108-
),
109-
);
11097
});
11198

11299
// Save relationships using a callback function.
113100
$this->saveRelationshipsUsing(static function (self $component, $state) {
114-
$relationship = $component->getRelationship();
115-
116-
// Check if the component's relationship is a BelongsTo relationship.
117-
if ($relationship instanceof BelongsTo) {
118-
$relationship->associate($state)->save();
101+
// Check if the component's relationship is a BelongsToMany relationship.
102+
if ($component->getRelationship() instanceof BelongsToMany) {
103+
// Wrap the state in a collection and convert it to an array if it's not set.
104+
$state = Collection::wrap($state ?? []);
119105

120-
return;
106+
// Sync the relationship with the provided state (IDs).
107+
$component->getRelationship()->sync($state->toArray());
121108
}
122-
123-
// Wrap the state in a collection and convert it to an array if it's not set.
124-
$state = Collection::wrap($state ?? []);
125-
126-
// Sync the relationship with the provided state (IDs).
127-
$component->getRelationship()->sync($state->toArray());
128109
});
129110

130111
$this->createOptionUsing(static function (SelectTree $component, array $data, Form $form) {

0 commit comments

Comments
 (0)