Skip to content

Self-referencing many-to-many pivot tables do not generate semantic relation names #323

@Rebal67

Description

@Rebal67

Environment:

Laravel: 10.x

PHP: 8.x

Reliese/Laravel: latest (after update)

relation_name_strategy set to 'foreign_key'

Using base mode

Migration examples:

Schema::create('company_following_company', function (Blueprint $table) { //which btw i would love it to be company_followings
    $table->foreignId('following_id')->constrained('companies')->cascadeOnDelete();
    $table->foreignId('follower_id')->constrained('companies')->cascadeOnDelete();
    $table->primary(['company_id', 'follower_id']);
});

Description of the issue:

Reliese generates a generic relation name (companies()) instead of semantic names (followers() / following()) for self-referencing many-to-many pivot tables, even when 'relation_name_strategy' => 'foreign_key' is set.

Expected behavior:

For a self-referencing many-to-many pivot table, Reliese should generate:

public function followers() { ... }
public function following() { ... }

Also the generated extra model doesnt extend type Pivot

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions