-
Notifications
You must be signed in to change notification settings - Fork 53
Open
Description
Hi, I'm trying to clone a model with relations that are MorphToMany but am getting an error on this. My Form model can be associated to many Site models in my project via a model called Siteable. My Siteable table looks like:
Schema::create('siteables', function (Blueprint $table) {
$table->ulid('id')->primary()->index();
$table->foreignUlid('site_id')->index()->constrained()->onUpdate('cascade')->onDelete('cascade');
$table->ulidMorphs('siteable');
$table->timestamps();
// define indexes for performance
$table->index(['site_id', 'siteable_type', 'siteable_id']);
$table->index('created_at');
});When trying to clone my Form, with the linked Siteable model, I get an error despite adding the following to my my Form model:
/**
* Set clonable relations
*
* @var string
*/
protected $cloneable_relations = [
'site'
];For reference, these are the two relations in my Form:
/**
* Get the site for the form
*/
public function site(): HasOneThrough
{
return $this->hasOneThrough(
Site::class,
Siteable::class,
'siteable_id',
'id',
'id',
'site_id'
)->where('siteable_type', Form::class);
}
/**
* Get all of the sites for the form.
*/
public function sites(): MorphToMany
{
return $this->morphToMany(Site::class, 'siteable')->withPivot('id');
}The error is:
Call to undefined method Illuminate\Database\Eloquent\Relations\HasOneThrough::save()
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels