@@ -252,12 +252,6 @@ public function afterGenerate(ConsoleStyle $io, array $params)
252252 // save the inverse side if it's being mapped
253253 if ($ newField ->getMapInverseRelation ()) {
254254 $ fileManagerOperations [$ otherManipulatorFilename ] = $ otherManipulator ;
255- } else {
256- // print message about it not being saved
257- $ fileManagerOperations [] = sprintf (
258- 'The inverse side of the relation was not mapped in "%s" because it lives in the vendor/ directory. ' ,
259- $ newField ->getInverseClass ()
260- );
261255 }
262256 $ currentFields [] = $ newFieldName ;
263257 } else {
@@ -579,8 +573,30 @@ function ($name) use ($targetClass) {
579573 return $ io ->confirm (sprintf ('Do you want to automatically delete orphaned <comment>%s</comment> objects (orphanRemoval)? ' , $ owningClass ), false );
580574 };
581575
582- $ setMapInverseSide = function (EntityRelation $ relation ) {
583- $ relation ->setMapInverseRelation (!$ this ->isClassInVendor ($ relation ->getInverseClass ()));
576+ $ askInverseSide = function (EntityRelation $ relation ) use ($ io ) {
577+ if ($ this ->isClassInVendor ($ relation ->getInverseClass ())) {
578+ $ relation ->setMapInverseRelation (false );
579+ }
580+
581+ // recommend an inverse side, except for OneToOne, where it's inefficient
582+ $ recommendMappingInverse = EntityRelation::ONE_TO_ONE === $ relation ->getType () ? false : true ;
583+
584+ $ getterMethodName = 'get ' .Str::asCamelCase (Str::getShortClassName ($ relation ->getOwningClass ()));
585+ if (EntityRelation::ONE_TO_ONE !== $ relation ->getType ()) {
586+ // pluralize!
587+ $ getterMethodName = Str::singularCamelCaseToPluralCamelCase ($ getterMethodName );
588+ }
589+ $ mapInverse = $ io ->confirm (
590+ sprintf (
591+ 'Do you want to add a new property to <comment>%s</comment> so that you can access/update <comment>%s</comment> objects from it - e.g. <comment>$%s->%s()</comment>? ' ,
592+ Str::getShortClassName ($ relation ->getInverseClass ()),
593+ Str::getShortClassName ($ relation ->getOwningClass ()),
594+ Str::asLowerCamelCase (Str::getShortClassName ($ relation ->getInverseClass ())),
595+ $ getterMethodName
596+ ),
597+ $ recommendMappingInverse
598+ );
599+ $ relation ->setMapInverseRelation ($ mapInverse );
584600 };
585601
586602 switch ($ type ) {
@@ -597,7 +613,7 @@ function ($name) use ($targetClass) {
597613 $ relation ->getOwningClass ()
598614 ));
599615
600- $ setMapInverseSide ($ relation );
616+ $ askInverseSide ($ relation );
601617 if ($ relation ->getMapInverseRelation ()) {
602618 $ io ->comment (sprintf (
603619 'A new property will also be added to the <comment>%s</comment> class so that you can access the related <comment>%s</comment> objects from it. ' ,
@@ -608,13 +624,14 @@ function ($name) use ($targetClass) {
608624 $ relation ->getInverseClass (),
609625 Str::singularCamelCaseToPluralCamelCase (Str::getShortClassName ($ relation ->getOwningClass ()))
610626 ));
611- }
612627
613- if (!$ relation ->isNullable ()) {
614- $ relation ->setOrphanRemoval ($ askOrphanRemoval (
615- $ relation ->getOwningClass (),
616- $ relation ->getInverseClass ()
617- ));
628+ // orphan removal only applies of the inverse relation is set
629+ if (!$ relation ->isNullable ()) {
630+ $ relation ->setOrphanRemoval ($ askOrphanRemoval (
631+ $ relation ->getOwningClass (),
632+ $ relation ->getInverseClass ()
633+ ));
634+ }
618635 }
619636
620637 break ;
@@ -658,7 +675,7 @@ function ($name) use ($targetClass) {
658675 );
659676 $ relation ->setOwningProperty ($ newFieldName );
660677
661- $ setMapInverseSide ($ relation );
678+ $ askInverseSide ($ relation );
662679 if ($ relation ->getMapInverseRelation ()) {
663680 $ io ->comment (sprintf (
664681 'A new property will also be added to the <comment>%s</comment> class so that you can access the related <comment>%s</comment> objects from it. ' ,
@@ -685,7 +702,7 @@ function ($name) use ($targetClass) {
685702 $ relation ->getOwningClass ()
686703 ));
687704
688- $ setMapInverseSide ($ relation );
705+ $ askInverseSide ($ relation );
689706 if ($ relation ->getMapInverseRelation ()) {
690707 $ io ->comment (sprintf (
691708 'A new property will also be added to the <comment>%s</comment> class so that you can access the related <comment>%s</comment> object from it. ' ,
0 commit comments