Merge pull request #10078 from filamentphp/fix/recursive-attach-relationship

fix: Recursively attach relationship
This commit is contained in:
Dan Harrin
2023-12-05 00:16:37 +00:00
committed by GitHub
2 changed files with 9 additions and 3 deletions
@@ -238,7 +238,10 @@ class AssociateAction extends Action
}
return $query->where(
$relationship->getParent()->getQualifiedKeyName(),
// https://github.com/filamentphp/filament/issues/8067
$relationship->getParent()->getTable() === $relationship->getRelated()->getTable() ?
$relationship->getParent()->getKeyName() :
$relationship->getParent()->getQualifiedKeyName(),
$relationship->getParent()->getKey(),
);
});
+5 -2
View File
@@ -233,8 +233,11 @@ class AttachAction extends Action
fn (Builder $query): Builder => $query->whereDoesntHave(
$table->getInverseRelationship(),
fn (Builder $query): Builder => $query->where(
$table->getRelationship()->getParent()->getQualifiedKeyName(),
$table->getRelationship()->getParent()->getKey(),
// https://github.com/filamentphp/filament/issues/8067
$relationship->getParent()->getTable() === $relationship->getRelated()->getTable() ?
$relationship->getParent()->getKeyName() :
$relationship->getParent()->getQualifiedKeyName(),
$relationship->getParent()->getKey(),
),
),
);