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

MorphTo Relation ignores parent $timestamp when touching #28638

Closed
tiwac100 opened this issue May 28, 2019 · 2 comments
Closed

MorphTo Relation ignores parent $timestamp when touching #28638

tiwac100 opened this issue May 28, 2019 · 2 comments
Labels

Comments

@tiwac100
Copy link

  • Laravel Version: 5.8.18
  • PHP Version: 7.3.2
  • Database Driver & Version: MySQL 5.7

Description:

When creating / updating / deleting a child belonging to a parent through a MorphTo relation Eloquent tries to updated the parents updated_at column regardless of the parents $timestamps property when the parent is listed in $touches.

Because this is a polymorphic relation and not all parents may have timestamps I would expect that parents with $timestamps = false are ignored when touching.

(I guess this may not only be relevant for MorphTo relations but others as well)

Steps To Reproduce:

Parent.php

class Parent extends Model
{
    public $timestamps = false;

    public function children(): MorphMany
    {
        return $this->morphMany(Child::class, 'children');
    }

}

Child.php

class Child extends Model
{
    protected $touches = ['parent'];

    public function parent(): MorphTo
    {
        return $this->morphTo();
    }

}

$parent->children()->save(new Child()); throws Illuminate\Database\QueryException: SQLSTATE[HY000]: General error: 1 no such column: updated_at (SQL: update "parents" set "updated_at" = 2019-05-28 11:02:21 where "parents"."id" = 1)

@driesvints driesvints added the bug label May 28, 2019
@driesvints
Copy link
Member

That indeed seems like a bug to me. Welcoming prs for this.

@driesvints
Copy link
Member

Pr for this was merged.

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

2 participants