TypeRocket / core

TypeRocket core source files where all the magic lives.
https://typerocket.com
36 stars 21 forks source link

Fix error when column name of Primary Key is different to 'id' #10

Closed kijamve closed 5 years ago

kevindees commented 6 years ago

Hey @kijamve

Thanks for summiting this PR. Looks like you had some failed unit tests. If you can fix those I can see about reviewing and then merging this one.

Thanks, Kevin

kijamve commented 6 years ago

Sorry, but you unit test has bad, the correct query is:

UPDATE wp_posts SET `post_title`='My Title' WHERE ID = 1

This is bad: UPDATE wp_posts SET post_title='My Title' WHERE ID = 1

And the same for other query and unit test.

kevindees commented 6 years ago

Hey @kijamve

Thanks for making some updates so I could review this. I'm curious why you decided to use back ticks. I had avoided them for a few reasons since they are optional in MySQL.

By adding these it might cause breaking changes for anyone using joins. With the current code join_table.column becomes or for anyone using them within the column name:

`join_table.column`

But it should be:

`join_table`.`column`

Also, some people might be using back ticks manually and so we would need to strip them out and then add them back in.

I'm interested to hear your thoughts.

Thanks, Kevin

kijamve commented 6 years ago

I have a table where a column has the name 'default', this generates conflicts in the Model when I do something like $obj->default = true; $obj->save();