Skip to content

Issue: SQL Error When Using hasManyThrough or belongsToMany in Activity Timeline Sidebar #99

@jangidgirish

Description

@jangidgirish

Package Version

v1.0.10

Laravel Version

v12.x.x

PHP Version

PHP 8.3.20

Problem description

I am attempting to add an activity timeline sidebar to a resource using the following code:

ActivityLogTimelineTableAction::make('Activities')
    ->withRelations(['hasManyThroughRelation', 'belongsToManyRelation']);

However, when using hasManyThrough or belongsToMany relationships, the timeline throws a SQL error:

SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'id' in SELECT is ambiguous

It seems the query generated does not alias the id column properly, returning ambiguity when joining tables. This issue only occurs when certain relationships like hasManyThrough or belongsToMany are used.

Image

Expected behavior

Expected Behavior:
The timeline should handle complex relationships without generating ambiguous column errors.

Steps to reproduce

Steps to Reproduce

  1. Create a Filament resource that includes an ActivityLogTimelineTableAction sidebar.

  2. In the table() method or corresponding section of your resource, define the timeline action like this:

    ActivityLogTimelineTableAction::make('Activities')
        ->withRelations(['hasManyThroughRelation', 'belongsToManyRelation']);
  3. Ensure that the specified relations (hasManyThroughRelation, belongsToManyRelation) are valid and defined in your model.

  4. Navigate to the resource page in the Filament admin panel.

  5. When the page loads, observe the error thrown:

    SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'id' in SELECT is ambiguous
    

This issue occurs due to unqualified id columns in the generated SQL query when using complex relationships like hasManyThrough or belongsToMany.

Reproduction repository (issue will be closed if this is not valid)

no

Relevant log output

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions