Closed mohaghegh closed 7 years ago
Can you please post your database scheme here?
Show Create Table hmk_provinces; Show Create Table hmk_countries;
Here's the schema.
"hmk_provinces" :
CREATE TABLE `hmk_provinces` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(250) DEFAULT NULL,
`country_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `idx_provinces` (`country_id`),
CONSTRAINT `fk_provinces` FOREIGN KEY (`country_id`) REFERENCES `hmk_countries` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8
"hmk_countries" :
CREATE TABLE `hmk_countries` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(250) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
Thank you for sharing the schema with us.
Unfortunately that is a current limitation in the code generator. Currently it automatically handles the belongsTo
relation between the objects.
However, this is something we are looking to implement in future release (possible in the next minor release.)
For now, you'll have to manually add the hasMany
relation on the Country model.
Thank you for your feedback and please keep them coming :)
Good. I'm sure it will be implemented as perfect as other parts of this handy code-generator :)
Watching for upcoming releases, with feedbacks and star ;)
@mohaghegh good news! This feature have been implemented in a separate branch (i.e v2.2dev) It is not ready to be released yet, but feel free to try it out https://github.com/CrestApps/laravel-code-generator/tree/v2.2dev
There are couple things that are worth mention
--fields-file
option in all command have been changed to --resource-file
since that file is no longer just a fields-file. But no worries, the system is still able to parse the old fields-file
format into the new resource-file
format.resource-file
. The resource-file
allows you to define any relations, indexes and fields all at one.create:fields-file
has been renamed to resource-file:from-database
fields-file:create
has been renamed to resource-file:create
fields-file:delete
has been renamed to resource-file:delete
fields-file:append
has been renamed to resource-file:append
fields-file:reduce
has been renamed to resource-file:reduce
Please let me know if you use it and if you encounter any unexpected bugs!
Thank you
I am closing this ticket for now since this feature will be part of the new coming up release version 2.2.0
For more info about the new release, http://crestapps.dev/laravel-code-generator/docs/2.2
Hi Regarding issue #3 , "hasMany" part of the ralationships are not generated when generating resources from existing database. In my project there are two tables: countries and provinces. Running this command:
php artisan create:resources Province --table-name hmk_provinces --table-exists --translation-for=en,fa --force
generates a nice model file containing country method:public function country() { return $this->belongsTo('App\Models\Country','country_id'); }
but the reverse method (e.g. provinces) is not generated in Country model file when running this command:php artisan create:resources Province --table-name hmk_provinces --table-exists --translation-for=en,fa --force
Am I going wrong way? Thanks a lot