Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: used new parent relation on instanceof control for has one through #15265

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions packages/forms/src/Components/Select.php
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the return type of getRelationship() need updating? Any other references to this class?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we did, I think we would need to retain both HasManyThrough and HasOneOrManyThrough on the return type for backwards compatibility, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! I fixed that too.

Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\Relations\HasOneOrMany;
use Illuminate\Database\Eloquent\Relations\HasOneOrManyThrough;
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
Expand Down Expand Up @@ -816,7 +817,7 @@ public function relationship(string | Closure | null $name = null, string | Clos

if (
($relationship instanceof BelongsToMany) ||
($relationship instanceof HasManyThrough)
($relationship instanceof (class_exists(HasOneOrManyThrough::class) ? HasOneOrManyThrough::class : HasManyThrough::class))
) {
if ($modifyQueryUsing) {
$component->evaluate($modifyQueryUsing, [
Expand Down Expand Up @@ -989,7 +990,7 @@ static function (Select $component): bool {

if (
($relationship instanceof HasOneOrMany) ||
($relationship instanceof HasManyThrough) ||
($relationship instanceof (class_exists(HasOneOrManyThrough::class) ? HasOneOrManyThrough::class : HasManyThrough::class)) ||
($relationship instanceof BelongsToThrough)
) {
return;
Expand Down Expand Up @@ -1269,7 +1270,7 @@ protected function getQualifiedRelatedKeyNameForRelationship(Relation $relations
return $relationship->getQualifiedRelatedKeyName();
}

if ($relationship instanceof HasManyThrough) {
if ($relationship instanceof (class_exists(HasOneOrManyThrough::class) ? HasOneOrManyThrough::class : HasManyThrough::class)) {
return $relationship->getQualifiedForeignKeyName();
}

Expand Down
3 changes: 2 additions & 1 deletion packages/panels/src/Resources/Pages/CreateRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
use Illuminate\Database\Eloquent\Relations\HasOneOrManyThrough;
use Illuminate\Support\Js;
use Throwable;

Expand Down Expand Up @@ -182,7 +183,7 @@ protected function associateRecordWithTenant(Model $record, Model $tenant): Mode
{
$relationship = static::getResource()::getTenantRelationship($tenant);

if ($relationship instanceof HasManyThrough) {
if ($relationship instanceof (class_exists(HasOneOrManyThrough::class) ? HasOneOrManyThrough::class : HasManyThrough::class)) {
$record->save();

return $record;
Expand Down
3 changes: 2 additions & 1 deletion packages/tables/src/Actions/CreateAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasOneOrManyThrough;
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
use Illuminate\Support\Arr;

Expand Down Expand Up @@ -66,7 +67,7 @@ protected function setUp(): void

if (
(! $relationship) ||
$relationship instanceof HasManyThrough
$relationship instanceof (class_exists(HasOneOrManyThrough::class) ? HasOneOrManyThrough::class : HasManyThrough::class)
) {
$record->save();

Expand Down
3 changes: 2 additions & 1 deletion packages/tables/src/Filters/Concerns/HasRelationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
use Illuminate\Database\Eloquent\Relations\HasOneOrManyThrough;
use Illuminate\Database\Eloquent\Relations\Relation;
use Znck\Eloquent\Relations\BelongsToThrough;

Expand Down Expand Up @@ -110,7 +111,7 @@ public function getRelationshipKey(?Builder $query = null): ?string
$relationship->getQualifiedRelatedKeyName();
}

if ($relationship instanceof HasManyThrough) {
if ($relationship instanceof (class_exists(HasOneOrManyThrough::class) ? HasOneOrManyThrough::class : HasManyThrough::class)) {
return $query?->getModel()->qualifyColumn($relationship->getForeignKeyName()) ??
$relationship->getQualifiedForeignKeyName();
}
Expand Down
3 changes: 2 additions & 1 deletion packages/tables/src/Table/Concerns/HasQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
use Illuminate\Database\Eloquent\Relations\HasOneOrMany;
use Illuminate\Database\Eloquent\Relations\HasOneOrManyThrough;
use Illuminate\Database\Eloquent\Relations\Relation;

use function Livewire\invade;
Expand Down Expand Up @@ -88,7 +89,7 @@ public function getRelationshipQuery(): ?Builder

$query = $relationship->getQuery();

if ($relationship instanceof HasManyThrough) {
if ($relationship instanceof (class_exists(HasOneOrManyThrough::class) ? HasOneOrManyThrough::class : HasManyThrough::class)) {
// https://github.com/laravel/framework/issues/4962
$query->select($query->getModel()->getTable() . '.*');

Expand Down