Comments (2)
Hi @WeaponX86,
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.
from laravel.
I should mention I'm running:
- PHP v7.3.3
- Laravel Zero v8.10.0
- reliese/laravel v1.1.6
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);
Here's another example of a table definition and the resulting model:
from laravel.
Related Issues (20)
- What about polymorphic relationships?
- Ability to exclude specific columns
- Issue when generating pivot models for tables with duplicated strings in their name
- Not generating views for Postgres HOT 1
- issue on save json field (array) HOT 2
- missing documentation / config example about template customisation
- primary key uuid => change $keyType HOT 1
- Dates property is deprecated since Laravel 8
- Hidden property not being generated in base Model files
- Typo in WhoDidIt referring to "udpated_by" instead of "updated_by" HOT 2
- Support for Enums HOT 1
- Model relationships not generated in Laravel 9
- Error when one of the MySQL table on the server have a "." in it's name HOT 1
- HasOneOrMany
- stancl/tenancy how use HOT 2
- Deprecated "dates" property HOT 1
- Datetime or Timestamp fields are mapped to classic date in casts
- Generating models with_property_constants doesn't work correctly
- error HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel.