beyondcode / invoker-community

74 stars 2 forks source link

can't find method on model that contains underscore #80

Open lightwalkernet opened 3 years ago

lightwalkernet commented 3 years ago

OS: darwin Invoker Version: 2.0.2 Laravel Version: 8.22.1 Local project: true PHP Binary: /usr/local/bin/php Route: /project/index?class=App%5CUser&time=1612386170472&project=local-4Ep3udexmFQ5tkqPLfdxkS

Error:

BadMethodCallException 

  Call to undefined method App\User::curaReports()

  at /Users/aaronkenton/websites/numinous/vendor/laravel/framework/src/Illuminate/Support/Traits/ForwardsCalls.php:50
     46▕      * @throws \BadMethodCallException
     47▕      */
     48▕     protected static function throwBadMethodCallException($method)
     49▕     {
  ➜  50▕         throw new BadMethodCallException(sprintf(
     51▕             'Call to undefined method %s::%s()', static::class, $method
     52▕         ));
     53▕     }
     54▕ }

  • Bad Method Call: Did you mean App\User::cura_reports() ? 

      +7 vendor frames 
  8   phar:/Applications/Invoker.app/Contents/Resources/invoker.phar/src/Actions/IndexResourceAction.php:129
      Illuminate\Database\Eloquent\Builder::withCount()

  9   phar:/Applications/Invoker.app/Contents/Resources/invoker.phar/src/Actions/IndexResourceAction.php:51
      _HumbugBoxe923e1c0def2\Invoker\Actions\IndexResourceAction::addWithCount()

In my user model the relationship is set up using this method:

  public function cura_reports()
    {
        return $this->hasMany(\App\Models\Cura\Reports::class);
    }

I am getting similar errors like the one above on other relationships. Is it throwing an error because of the underscore in the method name? I am using underscore because it allows me to seperate similar relationships for different domains in a multi tenancy app.

What would you suggest?

mpociot commented 3 years ago

Yeah, it's a bug because of the snake_case naming of your relation. I currently convert the relations to camelCase, when adding them as counts or eager load them. I'll look into this 👍

lightwalkernet commented 3 years ago

Thanks for looking into it.

lightwalkernet commented 3 years ago

Any news on this bug fix? Or should I change my naming convention?

aaronlord commented 3 years ago

Any ETA on this? Wish I'd known this before paying. Pretty big deal breaker.

lightwalkernet commented 3 years ago

I would agree. I was very excited about invoker but have not been able to use it since I purchased.