Skip to content

Issue with constrained() method used after foreignIdFor(), instead of table name when $table parameter is not passed uses column name#53144

Merged
taylorotwell merged 9 commits intolaravel:11.xfrom
granitibrahimi:patch-1
Oct 15, 2024
Merged

Issue with constrained() method used after foreignIdFor(), instead of table name when $table parameter is not passed uses column name#53144
taylorotwell merged 9 commits intolaravel:11.xfrom
granitibrahimi:patch-1

Conversation

@granitibrahimi
Copy link
Contributor

When constrained() is used after foreignIdFor() then on the migration query for the constrained instead of the table name uses column name and pluralise it.

$table->foreignIdFor(User::class, 'assigned_at')->nullable()->constrained();

Query produced to add the constrain:

alter table `tasks` add constraint `tasks_assigned_at_foreign` foreign key (`assigned_at`) references `assigned_ats` (`id`);

so instead of references users it produces references assigned_ats pluralised name of the column.

@granitibrahimi granitibrahimi marked this pull request as draft October 13, 2024 17:00
@granitibrahimi granitibrahimi marked this pull request as ready for review October 13, 2024 22:15
@taylorotwell taylorotwell merged commit f69a736 into laravel:11.x Oct 15, 2024
@morloderex
Copy link
Contributor

This pr broke our migrations.

@crynobone
Copy link
Member

This pr broke our migrations.

Can you submit a bug report with reproducing code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants