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

Unwanted indirect relationships are displayed when using HasOne relationship #5245

Closed
chimit opened this issue Jan 17, 2023 · 1 comment
Closed
Assignees
Labels
bug Verified bug by the Nova team

Comments

@chimit
Copy link

chimit commented Jan 17, 2023

  • Laravel Version: 9.47.0
  • Nova Version: 4.20.2
  • PHP Version: 8.1.9
  • Database Driver & Version: MySQL 8
  • Operating System and Version: macOS 13.1 (22C65)
  • Browser type and version: Safari 16.2 (18614.3.7.1.5)
  • Reproduction Repository: http://github.com/chimit/nova

Description:

If you have a HasOneThrough relationship between 2 models and display one of them in Nova as a resource all relationships of both resources are displayed at the same time as sections.

Detailed steps to reproduce the issue on a fresh Nova installation:

class Category extends Model
{
    /**
     * Get the building that owns the category.
     */
    public function building()
    {
        return $this->belongsTo(Building::class);
    }

    /**
     * Get the listing associated with the category.
     */
    public function listing()
    {
        return $this->hasOne(Listing::class);
    }
}
class Listing extends Model
{
    /**
     * Get the category for the listing.
     */
    public function category()
    {
        return $this->belongsTo(Category::class);
    }

    /**
     * Get the building that owns the listing.
     */
    public function building()
    {
        return $this->hasOneThrough(Building::class, Category::class, 'id', 'id', 'category_id', 'building_id');
    }
}
class Building extends Model
{
    /**
     * Get the categories for the building.
     */
    public function categories()
    {
        return $this->hasMany(Category::class);
    }

    /**
     * Get the listings for the building.
     */
    public function listings()
    {
        return $this->hasManyThrough(Listing::class, Category::class);
    }
}

I created very basic Nova resources for them that you can check in the reproduction repo:

class Category extends Resource
{
    // ...

    public function fields(NovaRequest $request)
    {
        return [
            ID::make()->sortable(),
            BelongsTo::make('Building'),
            HasOne::make('Listing'),
        ];
    }
}

And here is what I see in any Category page in Nova:

image

If you activate Action logs you would see multiple Action sections at the same time.

@chimit chimit changed the title Unwanted indirect relationships are displayed when using HasOneThrough Unwanted indirect relationships are displayed when using HasOne relationship Jan 17, 2023
@crynobone crynobone self-assigned this Jan 17, 2023
@crynobone crynobone added the bug Verified bug by the Nova team label Jan 17, 2023
@github-actions
Copy link

github-actions bot commented Feb 2, 2023

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Verified bug by the Nova team
Projects
None yet
Development

No branches or pull requests

2 participants