GithubHelp home page GithubHelp logo

Comments (2)

finiteinfinity avatar finiteinfinity commented on June 24, 2024

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.

WeaponX86 avatar WeaponX86 commented on June 24, 2024

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); 

Throws this error:
Screenshot 2022-07-14 113229

Here's another example of a table definition and the resulting model:
Screenshot 2022-07-14 114003

Screenshot 2022-07-14 113936

from laravel.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.