You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a table users and a table organizations. A user belongs to one organization. When I run I generate the models the relationship from users.org_id to organizations.org_id in the User model is wrong.
Try setting 'relation_name_strategy' => 'foreign_key' in the models.php config file please?
I'm not 100% this will solve your issue, but setting that config value should use the foreign key name (where possible) to generate the relation names instead - which I'm hoping solves your naming issues.
I have "relation_name_strategy" set to "foreign_key" already. The only other thing I changed in the config was setting the namespace: 'namespace' => 'App\Models\Shard',
My database contains 346 tables with 501 total foreign keys. All keys are named like {TABLE}_ibfk_{INT}. All of the generated models just get dumped with the column name for the method which is unusable because it conflicts with the actual column name attribute.
I generated the models like this: php artisan code:models --schema=my_schema
Example code:
$org = User::firstWhere('user_id', 254)
->with('org_id')
->get();
//Log::debug($org); // Array with one object
Log::debug('Organization name: '.$org[0]->org_id->org_name);
Throws this error:
Here's another example of a table definition and the resulting model:
I have a table users and a table organizations. A user belongs to one organization. When I run I generate the models the relationship from users.org_id to organizations.org_id in the User model is wrong.
In User.php the relationship name is the same as the source column name so I can't use it.
This works though:
I cannot change the target column name organizations.org_id. This is an existing DB I inherited.
The text was updated successfully, but these errors were encountered: