Skip to content

Incrementing argument in Table attribute doesn't work for Pivot models #59335

@Propaganistas

Description

@Propaganistas

Laravel Version

13.1.1

PHP Version

8.5.2

Database Driver & Version

No response

Description

The #[Table] attribute includes an argument to specify whether the primary key should be incrementing, in favor of the old property style declaration.

Pivot models are set to non-incrementing by default:

class Pivot extends Model
{
use AsPivot;
/**
* Indicates if the IDs are auto-incrementing.
*
* @var bool
*/
public $incrementing = false;

Using #[Table] to configure that a Pivot model should still be incrementing however doesn't work out. The $incrementing property in parent Pivot class still takes precedence and prevents the attribute's incrementing argument from actually firing:

if ($this->incrementing === true) {
if (static::resolveClassAttribute(WithoutIncrementing::class) !== null) {
$this->incrementing = false;
} elseif ($table && $table->incrementing !== null) {
$this->incrementing = $table->incrementing;
}
}

Steps To Reproduce

#[Table(incrementing: true)]
class MyModel extends Pivot {}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions