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

Nullable polymorphic relationship combined with $touches generates incorrect query #25434

Closed
jerguslejko opened this issue Sep 3, 2018 · 0 comments

Comments

@jerguslejko
Copy link
Contributor

jerguslejko commented Sep 3, 2018

  • Laravel Version: 5.6.37
  • PHP Version: 7.2.9
  • Database Driver & Version: mysql & 5.7.23

Description:

When using an inverse of a nullable polymorphic (morphTo()) relationship along side with $touches on the relationship, Laravel generates incorrect query for touching the relationship.

Steps To Reproduce:

  1. Create tags table with nullable taggable fields:

    Schema::create('tags', function (Blueprint $table) {
        $table->increments('id');
    
        $table->nullableMorphs('taggable');
    
        $table->timestamps();
    });
  2. Create Tag model with taggable() relationship and $touches property set to ['taggable']

    class Tag extends Model
    {  
        protected $touches = ['taggable'];
    
        public function taggable()
        {
            return $this->morphTo();
        }
    }
  3. Now try to create a new Tag

    Tag::create();

This generates the following error:

Illuminate/Database/QueryException with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'tags.' in 'where clause' (SQL: update `tags` set `updated_at` = 2018-09-03 20:31:36 where `tags`.`` is null)'

Thanks for looking into this

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

No branches or pull requests

1 participant