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

Call to undefined method Illuminate\Database\Eloquent\Relations\HasOneThrough::save() #62

Open
sts-ryan-holton opened this issue Jul 22, 2024 · 0 comments

Comments

@sts-ryan-holton
Copy link

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()

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