Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Camel case model relationship is returned as snake case property #13614

Closed
klimentLambevski opened this issue May 18, 2016 · 4 comments
Closed

Comments

@klimentLambevski
Copy link

How can i tell laravel to return the relationship results in same name as the relationship function?
ex. I have relationship called mediaItem and when i call $model->with('mediaItem') is is returned as {media_item: {}}. Is there a way that it is returned as {mediaItem:{}}?

@GrahamCampbell
Copy link
Member

No, sorry.

@stefankorun
Copy link

@GrahamCampbell Isn't public static $snakeAttributes = false; attribute the solution to this?

ref: https://github.com/laravel/framework/blob/5.2/src/Illuminate/Database/Eloquent/Model.php#L204

@josemiguelq
Copy link

@klimentLambevski you can solve this using:

Network.php

  public function pointsOfSale()
    {
        return $this->hasMany(PointOfSale::class);
    }

PointOfSale.php

 public function network()
    {
        return $this->belongsTo(Network::class, 'networkId');
    }

@DamianSuess
Copy link

I wish this worked for the Factory and Seeder, it still converts it to "network_Id". The system doesn't care that our naming conventions don't use snake_case

@klimentLambevski you can solve this using:

Network.php

  public function pointsOfSale()
    {
        return $this->hasMany(PointOfSale::class);
    }

PointOfSale.php

 public function network()
    {
        return $this->belongsTo(Network::class, 'networkId');
    }

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

No branches or pull requests

5 participants