Skip to content

$withCount breaks replicate() #26562

Closed
Closed
@tobz-nz

Description

@tobz-nz
  • Laravel Version: 5.7.13
  • PHP Version: 7.2.9
  • Database Driver & Version: mysql / ?

Description:

As in other cases(that have all been fixed I think), a model with a polymorphic relation and a $withCount property fails to replicate()

Steps To Reproduce:

class Board extends Model {
public $withCount = ['profiles'];
public function profiles()
    {
        return $this->morphedByMany(User::class, 'profilable');
    }
}

$b = Board::first();
$b2 = $b->replicate();
$b2->save();

Results in the error:
Column not found: 1054 Unknown column 'profiles_count' in 'field list' ...

Expected $b2 to be a new Board instance with same properties as original.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions