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

Can not specify a custom pivotModel in Many To Many Polymorphic relations #3485

Closed
Tracked by #65
iboved opened this issue Apr 4, 2018 · 2 comments
Closed
Tracked by #65

Comments

@iboved
Copy link

iboved commented Apr 4, 2018

Expected behavior

I want to add my custom "pivotModel" to Many To Many Polymorphic relation. Here is my Model definitions and migration structure. When I get the collection of categories, the category has \Illuminate\Database\Eloquent\Relations\MorphPivot instead of the pivot model I provided. I found out that here "$using" is always null.
I found out that in Laravel we can specify a custom pivot model with "using()" method like this:

    public function users()
    {
        return $this->belongsToMany('App\User')->using('App\UserRole');
    }

Here we call using() Laravel method and set "$using" property. But in OctoberCMS we can not set pivotModel via using() method. And that's why we always have "$using" equal to null here.

Actual behavior

When I get the collection of categories, the category has \Illuminate\Database\Eloquent\Relations\MorphPivot instead of the pivot model I provided.

Reproduce steps

Create application structure like here. And try to set your own custom pivotModel.

October build

October build: 434

@LukeTowers
Copy link
Contributor

This is because a pivot model for a MorphToMany relationship for Laravel is different from a pivot model used for the belongsToMany relationship. October has not implemented a mirror for this so it won't work in that case.

This is something that would be welcomed though if you were willing to dive into the library code (octobercms/library) and provide a PR to implement it. Here is Laravel's relationship implementation: https://github.com/laravel/framework/blob/56a58e0fa3d845bb992d7c64ac9bb6d0c24b745a/src/Illuminate/Database/Eloquent/Relations/MorphToMany.php#L128-L147 and October would also need a MorphPivot model extending Laravel's MorphPivot model.

@bennothommo
Copy link
Contributor

Closing as it has been over a month since any activity on this occurred and we are trying to figure out what issues are still relevant. If this is still something that you would like to see through to fruition please respond and we can get the ball rolling.

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

No branches or pull requests

3 participants