Skip to content

Fluent orderBy doesn't convert camelCase to snake_case #391

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

Closed
assertchris opened this issue Feb 20, 2013 · 11 comments
Closed

Fluent orderBy doesn't convert camelCase to snake_case #391

assertchris opened this issue Feb 20, 2013 · 11 comments

Comments

@assertchris
Copy link
Contributor

The field is last_name and ->orderBy("lastName", "asc") errors....

@franzliedke
Copy link
Contributor

Sad to say this, but this whole camel-casing thing is really turning into a mess.

@conradkleinespel
Copy link
Contributor

👍 @franzliedke. I've set up email notifications for Laravel so I can check out PRs and issues. Half of them seem to be somehow related to snake / camel casing. It's getting pretty annoying.

I don't get how converting to snake case makes things any better (not that it bothers me, I use snake case anyway...). Could we please have your input on this @taylorotwell ?

@Anahkiasen
Copy link
Contributor

Yup, I'd rather strip out the feature and let users deal with it themselves, this is getting out of hand in my opinion.

@alexwhitman
Copy link
Contributor

PSR-0 only defines that the 'PHP' bits are camel case. In this case it's a string which would be correct if using camel case columns in the DB.

@assertchris
Copy link
Contributor Author

@alexwhitman It's not about what needs to be camelCase or snake_case, but rather the consistency with which the snake_case to camelCase transformations are applied in cohesive behaviors. If I can treat last_name as if it were lastName in object accessors and model assignment then I should be able to do it in fluent methods also...

@alexwhitman
Copy link
Contributor

That's certainly true but getters/setters are a different issue from your original example of ->orderBy("lastName", "asc") which shouldn't be converted.

@assertchris
Copy link
Contributor Author

@alexwhitman you can currently use ->where("createdAt", "=", "2013-02-20 13:12:18") which will filter on the created_at field...

@alexwhitman
Copy link
Contributor

In that case disregard what I've just said.

I've only been developing new apps with Laravel but this would make it hard to work with some legacy apps that have strange column naming schemes (or rather lack of naming schemes) and so probably should be removed.

@taylorotwell
Copy link
Member

Eloquent has always required snake_case column names, and Laravel 4 is no different. PSR doesn't even dictate property names, and actually states that they can be either snake_case or camelCase. Just use snake_case with Eloquent like you always have. It's really not that complicated I don't think.

@assertchris
Copy link
Contributor Author

I don't mind juggling that sort of thing. The the point of this issue is that ->where("lastName", "=", "pitt") and ->orderBy("last_name", "asc") are inconsistent.

@taylorotwell
Copy link
Member

Just use the casing of your database fields. There is no magic going on.

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

6 participants