Framework: [5.4] ambiguous updated_at column on relationship

Created on 27 Feb 2017  路  2Comments  路  Source: laravel/framework

  • Standalone illuminate/database: 5.4.13
  • PHP Version: 7.1
  • Database Driver & Version: Mysql 5.7

Description:

When creating a BelongsToMany Relationship and then trying to delete all related models, it fails with:

SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'updated_at' in field list is ambiguous (SQL: update `group` inner join `user_group` on `group`.`id` = `user_group`.`group_id` set `group`.`deleted_at` = 2017-02-27 21:04:25, `updated_at` = 2017-02-27 21:04:25 where `user_group`.`user_id` = 1 and `group`.`deleted_at` is null)

Steps To Reproduce:

  • Create a User Model
  • Create a belongsToMany Relationship with a X Model
  • Create a belongsToMany Relationship with a Y Model
  • Timestamps on all Models enabled (created_at, updated_at, deleted_at)
  • enable Softdeletes for all Models
  • cast as dates: (created_at, updated_at, deleted_at)
  • attach some X Models and some Y Models to the User
  • add a reset method to the User Model
  • execute within reset:
$this->x()->delete();
$this->y()->delete();

Both queries fail with the ambiguous updated_at. If you look at the error you can see the missing group. in front of updated_at.

Edit:
When i execute ->forceDelete() instead of ->delete() it works like a charm.

Thanks!

Most helpful comment

All 2 comments

Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Anahkiasen picture Anahkiasen  路  3Comments

shopblocks picture shopblocks  路  3Comments

felixsanz picture felixsanz  路  3Comments

SachinAgarwal1337 picture SachinAgarwal1337  路  3Comments

JamborJan picture JamborJan  路  3Comments