I have a many-to-many relationship of Users and Notices set up in Eloquent. The pivot table has timestamps and a 'read' field (so each user can mark a notice as read independently). Here are the relevant model definitions:
class Notice extends Model
{
public function users()
{
return $this->belongsToMany('App\Entities\User', 'notice_user_map')
->withPivot('read')
->withTimestamps();
}
}
class User extends Model implements AuthenticatableContract, AuthorizableContract, CanResetPasswordContract
{
public function notices()
{
return $this->belongsToMany('App\Entities\Notice', 'notice_user_map')
->withPivot('read')
->withTimestamps();
}
}
However, when I try to mark all notices for a user as read I get an error. The code I'm using is
$user->notices()->wherePivot('read', 0)->update(['read' => 1]);
The error is
Integrity constraint violation: 1052 Column 'updated_at' in field list is ambiguous (SQL: update
noticesinner joinnotice_user_maponnotices.id=notice_user_map.notice_idsetread= 1,updated_at= 2016-01-06 23:49:45 wherenotice_user_map.user_id= 2904708423 andnotice_user_map.read= 0)
The columns that are set should have the table prefix, i.e. notice_user_map.read and notice_user_map.updated_at
Also the date isn't quoted, not sure if that's the exact query that was trying to be run or if that's just how Laravel is displaying it.
Laravel 5.1, PHP 5.5, MySQL 5.6
Have the same problem , using a hasManyThrough relationship.
Also mentioned here but marked as closed: #5440 .
Laravel 5.2.29, PHP 5.5, MySQL 5.6
I still have this issue
SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'updated_at' in field list is ambiguous
Even i am not many-to-many relation
Most helpful comment
I still have this issue
SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'updated_at' in field list is ambiguous
Even i am not many-to-many relation