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

[7.x] Allow to use alias of morphed model #34032

Merged
merged 2 commits into from Aug 27, 2020

Commits on Aug 27, 2020

  1. Allow to use alias of morphed model

    At the moment if you use hasMorph() you need to use model class name and can't use alias, you need to use `Relation::getMorphedModel`.
    But this is already done when you use `*` which auto discover morphed relations.
    
    Moving this conversion for all case allow to use directly aliases.
    
    Example now:
    
    
    ```
            $morphable =  [
                    "App\AnotherModel",
                    Relation::getMorphedModel('alias')
            ];
            $dataset = MyModel::query()
                ->whereHasMorph('morphable', $morphable)
                ->with('morphable')
                ->orderBy('id')
                ->limit(50)
                ->get()
                ->groupBy('morphable_type');
    ```
    
    With this change can be:
    
    ```
            $morphable =  [
                    "App\AnotherModel",
                    'alias',
                    'another',
                    "App\YetAnotherModel",
            ];
            $dataset = MyModel::query()
                ->whereHasMorph('morphable', $morphable)
                ->with('morphable')
                ->orderBy('id')
                ->limit(50)
                ->get()
                ->groupBy('morphable_type');
    ```
    thewebartisan7 committed Aug 27, 2020
    Copy the full SHA
    aeeef89 View commit details
    Browse the repository at this point in the history
  2. Copy the full SHA
    62db293 View commit details
    Browse the repository at this point in the history