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
Snake Case Model relationships don't appear to work #4307
Comments
This is the method that's causing the issue you see: https://github.com/laravel/framework/blob/master/src/Illuminate/Database/Eloquent/Model.php#L2249. Basically what is happening is Eloquent is looking for an attribute called all_posts. Since it doesn't exists, it actually converts all_posts to allPosts and looks up a relationship method with that name instead of with all_posts. I'm not exactly sure why it was done this way, but it was. Also Laravel encourages the use of camelCase method names anyway. A quick glance at the code makes it look like if you had a relationship method named allPosts, you could actually use |
All methods should be camelCase per PSR-1. |
Good to know... Thanks! :-D |
I've just come across the following oddness. If I define a Model thusly:
When I do the following
I get a collection back. But, if I use the snake-cased all_posts method/var I get a null. E.g.
Is this a bug or a feature?
The text was updated successfully, but these errors were encountered: