Skip to content
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

Timestamps are not prefixed when updating many-to-many relationship #11815

Closed
svivian opened this issue Jan 11, 2016 · 2 comments
Closed

Timestamps are not prefixed when updating many-to-many relationship #11815

svivian opened this issue Jan 11, 2016 · 2 comments
Labels

Comments

@svivian
Copy link

svivian commented Jan 11, 2016

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 notices inner join notice_user_map on notices.id = notice_user_map.notice_id set read = 1, updated_at = 2016-01-06 23:49:45 where notice_user_map.user_id = 2904708423 and notice_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

@patroklosk
Copy link

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

samrap pushed a commit to samrap/framework that referenced this issue May 11, 2016
taylorotwell pushed a commit that referenced this issue May 18, 2016
* Fix issue [#11815](#11815)

* Fix failed StyleCI analysis.
symfony-splitter pushed a commit to illuminate/database that referenced this issue May 18, 2016
* Fix issue [#11815](laravel/framework#11815)

* Fix failed StyleCI analysis.
taylorotwell added a commit that referenced this issue May 26, 2016
@Amina24
Copy link

Amina24 commented Mar 22, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants