@@ -235,12 +235,6 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
235
235
// save the inverse side if it's being mapped
236
236
if ($ newField ->getMapInverseRelation ()) {
237
237
$ fileManagerOperations [$ otherManipulatorFilename ] = $ otherManipulator ;
238
- } else {
239
- // print message about it not being saved
240
- $ fileManagerOperations [] = sprintf (
241
- 'The inverse side of the relation was not mapped in "%s" because it lives in the vendor/ directory. ' ,
242
- $ newField ->getInverseClass ()
243
- );
244
238
}
245
239
$ currentFields [] = $ newFieldName ;
246
240
} else {
@@ -554,8 +548,30 @@ function ($name) use ($targetClass) {
554
548
return $ io ->confirm (sprintf ('Do you want to automatically delete orphaned <comment>%s</comment> objects (orphanRemoval)? ' , $ owningClass ), false );
555
549
};
556
550
557
- $ setMapInverseSide = function (EntityRelation $ relation ) {
558
- $ relation ->setMapInverseRelation (!$ this ->isClassInVendor ($ relation ->getInverseClass ()));
551
+ $ askInverseSide = function (EntityRelation $ relation ) use ($ io ) {
552
+ if ($ this ->isClassInVendor ($ relation ->getInverseClass ())) {
553
+ $ relation ->setMapInverseRelation (false );
554
+ }
555
+
556
+ // recommend an inverse side, except for OneToOne, where it's inefficient
557
+ $ recommendMappingInverse = EntityRelation::ONE_TO_ONE === $ relation ->getType () ? false : true ;
558
+
559
+ $ getterMethodName = 'get ' .Str::asCamelCase (Str::getShortClassName ($ relation ->getOwningClass ()));
560
+ if (EntityRelation::ONE_TO_ONE !== $ relation ->getType ()) {
561
+ // pluralize!
562
+ $ getterMethodName = Str::singularCamelCaseToPluralCamelCase ($ getterMethodName );
563
+ }
564
+ $ mapInverse = $ io ->confirm (
565
+ sprintf (
566
+ '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>? ' ,
567
+ Str::getShortClassName ($ relation ->getInverseClass ()),
568
+ Str::getShortClassName ($ relation ->getOwningClass ()),
569
+ Str::asLowerCamelCase (Str::getShortClassName ($ relation ->getInverseClass ())),
570
+ $ getterMethodName
571
+ ),
572
+ $ recommendMappingInverse
573
+ );
574
+ $ relation ->setMapInverseRelation ($ mapInverse );
559
575
};
560
576
561
577
switch ($ type ) {
@@ -572,7 +588,7 @@ function ($name) use ($targetClass) {
572
588
$ relation ->getOwningClass ()
573
589
));
574
590
575
- $ setMapInverseSide ($ relation );
591
+ $ askInverseSide ($ relation );
576
592
if ($ relation ->getMapInverseRelation ()) {
577
593
$ io ->comment (sprintf (
578
594
'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. ' ,
@@ -583,13 +599,14 @@ function ($name) use ($targetClass) {
583
599
$ relation ->getInverseClass (),
584
600
Str::singularCamelCaseToPluralCamelCase (Str::getShortClassName ($ relation ->getOwningClass ()))
585
601
));
586
- }
587
602
588
- if (!$ relation ->isNullable ()) {
589
- $ relation ->setOrphanRemoval ($ askOrphanRemoval (
590
- $ relation ->getOwningClass (),
591
- $ relation ->getInverseClass ()
592
- ));
603
+ // orphan removal only applies of the inverse relation is set
604
+ if (!$ relation ->isNullable ()) {
605
+ $ relation ->setOrphanRemoval ($ askOrphanRemoval (
606
+ $ relation ->getOwningClass (),
607
+ $ relation ->getInverseClass ()
608
+ ));
609
+ }
593
610
}
594
611
595
612
break ;
@@ -633,7 +650,7 @@ function ($name) use ($targetClass) {
633
650
);
634
651
$ relation ->setOwningProperty ($ newFieldName );
635
652
636
- $ setMapInverseSide ($ relation );
653
+ $ askInverseSide ($ relation );
637
654
if ($ relation ->getMapInverseRelation ()) {
638
655
$ io ->comment (sprintf (
639
656
'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. ' ,
@@ -660,7 +677,7 @@ function ($name) use ($targetClass) {
660
677
$ relation ->getOwningClass ()
661
678
));
662
679
663
- $ setMapInverseSide ($ relation );
680
+ $ askInverseSide ($ relation );
664
681
if ($ relation ->getMapInverseRelation ()) {
665
682
$ io ->comment (sprintf (
666
683
'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