-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
updated_at not fully qualified, creates ambiguous column errors #13909
Comments
You can disable $timestamps on specific models by doing this: One question though, why are you using join when updating or deleting a row? Can you describe in detail the exact scenario? |
There was an attempt to fix a similar issue: #13519 So the fix was reverted: d12c4bb I don't think there'll be an easy solution for this as using a fully qualified column name |
This seems like a pretty major issue. Maybe I'm using Eloquent wrong, but with just a simple use of Eloquent like this: |
Yeah it is definitely an issue. The commit referenced by @themsaid was mine, and while I haven't had the time to revisit this issue I am going to devote the time to look for a fix regardless. Anyone who wants to work together to find a solution, you can find contact info on my profile. Really determined to get this resolved. |
The only thing that comes to the top of my head is in the Eloquent Model's The more long-term way would probably be defining the Eloquent Builder as an abstract class and then each driver has its own implementation of the |
@samrap Did you get the chance to open a PR? |
@themsaid Unfortunately not but I'd be happy to work together with you in order to develop a solution. From what I've discovered with this bug it's a much larger issue than it sounds. |
@themsaid I don't have experience outside of MySQL but if I get a list of the different qualified column name rules between drivers I think I can handle fixing this issue on my own. |
This seems to be an edge case and there hasn't been a fix yet. |
@trandaihung that's what I personally do, I tried to fix before but every database driver has different rules for the qualified column name which makes this change pretty major. |
Aw, I've to use |
Can a method ->withoutTimestamps() be added for this particular case? |
I've ran into this issue today as well. |
@srmklive the join in my case is generated because I have a belongsToMany relation in my model. When soft-deleting the model, the relation also gets soft-deleted. @samrap I noticed however the deleted_at column is properly qualified in the delete query, where the updated_at column isn't. Is this the also the case for other scenario's? Why isn't updated_at qualified the same way as the deleted_at column? |
@walterdeboer My PR to fix the issue explains what is going on in-depth: #13519 Unfortunately, as @themsaid mentioned above, the PR caused a problem when using the Postgres and Sqlite drivers. |
Have this issue as well |
I'm able to sidestep the ambiguity of the updated_at columns in Laravel 5.3 with a toBase() call on the Eloquent builder before doing an update. |
Same problem here. As a workaround had to pluck the ids for the result that i want to update with a select and then update the model with the given ids.
|
Same issue here |
This issue is affecting be on L5.4.36, and also should affect L5.5
This will bring ambiguous column error for |
We're all well aware this issue exists. Can we refrain from unconstructive comments of the type "same thing happening here" from this point forward? There are lots of people subscribed to these issue threads that don't need to be getting emails every time someone reconfirms this is a bug 😬 |
I am using the L5.4.36 and the workaround provided from @Turaylon is not feasible as it could get on the millions of ids on the current project and also the update values come from other tables that will be deprecated I ended up using a ReflectionClass to "disable" the timestamps for the model on the source model for the query builder:
This is not a long term approach or solution, but it bypass the timestamp modification. by not updating that field at all. A driver aware implementation (or an alternative to the array splitting) of the |
I've used method toBase() before update |
@samrap I'm happy to help you solve this problem if you're still looking to solve it. I would also be hesitant about the function |
@slaughter550 I would definitely be interested in working together on a solution. I'll shoot you an email. |
Its still happening, with Lumen 5.5 any news? |
Sound's good to me, @staudenmeir can you make such a PR ? |
Will be fixed in Laravel 5.8: #26031 |
Thanks @staudenmeir |
This works very nice for me. I am using Laravel 5.7 |
Keep in mind that |
When attempting to use delete() or update() on an eloquent model you can not use any joins because you will get an ambiguous column name error on updated_at. This is because the Eloquent/Builder.php does not prefix updated_at with the proper table name. I attempted to do a pull request for this, but the issue is further complicated by Arr::add (used in addUpdatedAtColumn) doing automatic dot notation exploding. This prevents me from adding a table.columnName string similar to the operation of SoftDeletes trait.
Laravel 5.2
The text was updated successfully, but these errors were encountered: