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

Generate Scaffold from table fails writing PHPDocType because relations #457

Closed
casivaagustin-zz opened this issue Aug 8, 2017 · 6 comments

Comments

@casivaagustin-zz
Copy link

I have this table

CREATE TABLE `devices` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `device` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
  `imsi` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `imei` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `udid` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `pushId` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `os` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `user_id` int(10) unsigned NOT NULL,
  PRIMARY KEY (`id`),
  KEY `devices_user_id_foreign` (`user_id`),
  CONSTRAINT `devices_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci

That has a relationship to users with the user_id field.

I'm trying to generate the scaffold for that table with this command

artisan infyom:scaffold Device --fromTable --tableName=devices

And I'm getting this error

  [ErrorException]     
  Undefined offset: 1  

Doing a little of research I have this trace

vagrant@local:~/Code/api$ artisan infyom:scaffold Device --fromTable --tableName=devices -vvv

                       
  [ErrorException]     
  Undefined offset: 1  
                       

Exception trace:
 () at /home/vagrant/Code/api/vendor/infyomlabs/laravel-generator/src/Generators/ModelGenerator.php:154
 Illuminate\Foundation\Bootstrap\HandleExceptions->handleError() at /home/vagrant/Code/api/vendor/infyomlabs/laravel-generator/src/Generators/ModelGenerator.php:154
 InfyOm\Generator\Generators\ModelGenerator->getPHPDocType() at /home/vagrant/Code/api/vendor/infyomlabs/laravel-generator/src/Generators/ModelGenerator.php:129
 InfyOm\Generator\Generators\ModelGenerator->fillDocs() at /home/vagrant/Code/api/vendor/infyomlabs/laravel-generator/src/Generators/ModelGenerator.php:68
 InfyOm\Generator\Generators\ModelGenerator->fillTemplate() at /home/vagrant/Code/api/vendor/infyomlabs/laravel-generator/src/Generators/ModelGenerator.php:46
 InfyOm\Generator\Generators\ModelGenerator->generate() at /home/vagrant/Code/api/vendor/infyomlabs/laravel-generator/src/Commands/BaseCommand.php:66
 InfyOm\Generator\Commands\BaseCommand->generateCommonItems() at /home/vagrant/Code/api/vendor/infyomlabs/laravel-generator/src/Commands/Scaffold/ScaffoldGeneratorCommand.php:44
 InfyOm\Generator\Commands\Scaffold\ScaffoldGeneratorCommand->handle() at n/a:n/a
 call_user_func_array() at /home/vagrant/Code/api/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:29
 Illuminate\Container\BoundMethod::Illuminate\Container\{closure}() at /home/vagrant/Code/api/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:87
 Illuminate\Container\BoundMethod::callBoundMethod() at /home/vagrant/Code/api/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:31
 Illuminate\Container\BoundMethod::call() at /home/vagrant/Code/api/vendor/laravel/framework/src/Illuminate/Container/Container.php:539
 Illuminate\Container\Container->call() at /home/vagrant/Code/api/vendor/laravel/framework/src/Illuminate/Console/Command.php:182
 Illuminate\Console\Command->execute() at /home/vagrant/Code/api/vendor/symfony/console/Command/Command.php:264
 Symfony\Component\Console\Command\Command->run() at /home/vagrant/Code/api/vendor/laravel/framework/src/Illuminate/Console/Command.php:167
 Illuminate\Console\Command->run() at /home/vagrant/Code/api/vendor/symfony/console/Application.php:874
 Symfony\Component\Console\Application->doRunCommand() at /home/vagrant/Code/api/vendor/symfony/console/Application.php:228
 Symfony\Component\Console\Application->doRun() at /home/vagrant/Code/api/vendor/symfony/console/Application.php:130
 Symfony\Component\Console\Application->run() at /home/vagrant/Code/api/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:122
 Illuminate\Foundation\Console\Kernel->handle() at /home/vagrant/Code/api/artisan:35

Looking into the getPHPDocType method i see this line

            case 'mt1':
                return camel_case($relation->inputs[1].' '.camel_case($relation->inputs[1]));

Doing a var_dump over relation to see what is having I got this

object(InfyOm\Generator\Common\GeneratorFieldRelation)#1146 (2) {
  ["type"]=>
  string(3) "mt1"
  ["inputs"]=>
  array(1) {
    [0]=>
    string(4) "User"
  }
}

As you can see there is no element 1.

I can not get more information to solve this issue, not sure why is expecting something in the position 1.

Hope the information helps to solve this issue.

Regards

@keskin
Copy link

keskin commented Aug 10, 2017

+1

@ekohere
Copy link

ekohere commented Aug 18, 2017

+1

@dhcmega
Copy link

dhcmega commented Aug 18, 2017

same problem

@mitulgolakiya
Copy link
Member

I will be working on this soon and will try to get this out this weekend.

@mitulgolakiya
Copy link
Member

@casivaagustin @dhcmega just fixed the issue. Get the latest code and let me know if you face any problem.

@dhcmega
Copy link

dhcmega commented Aug 21, 2017

working. thanks!

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

No branches or pull requests

5 participants