@@ -36,8 +36,17 @@ public function __construct(ORMInterface $orm, string $role, string $name, strin
3636 public function prepare (Pool $ pool , Tuple $ tuple , mixed $ related , bool $ load = true ): void
3737 {
3838 $ state = $ tuple ->state ;
39-
4039 $ relName = $ this ->getName ();
40+
41+ if (SpecialValue::isNotSet ($ related )) {
42+ if (!$ state ->hasRelation ($ relName )) {
43+ $ state ->setRelationStatus ($ relName , RelationInterface::STATUS_DEFERRED );
44+ return ;
45+ }
46+
47+ $ related = $ state ->getRelation ($ relName );
48+ }
49+
4150 if ($ state ->hasRelation ($ relName )) {
4251 $ prefill = $ state ->getRelation ($ relName );
4352 $ nodeValue = $ tuple ->node ->getRelation ($ relName );
@@ -70,11 +79,18 @@ public function prepare(Pool $pool, Tuple $tuple, mixed $related, bool $load = t
7079 public function queue (Pool $ pool , Tuple $ tuple ): void
7180 {
7281 $ state = $ tuple ->state ;
73- $ related = $ state ->getRelation ($ this ->getName ());
82+ $ relName = $ this ->getName ();
83+
84+ if (!$ state ->hasRelation ($ relName )) {
85+ $ state ->setRelationStatus ($ relName , RelationInterface::STATUS_RESOLVED );
86+ return ;
87+ }
88+
89+ $ related = $ state ->getRelation ($ relName );
7490
7591 if ($ related instanceof ReferenceInterface && $ related ->hasValue ()) {
7692 $ related = $ related ->getValue ();
77- $ state ->setRelation ($ this -> getName () , $ related );
93+ $ state ->setRelation ($ relName , $ related );
7894 }
7995 if ($ related === null ) {
8096 $ this ->setNullFromRelated ($ tuple , false );
@@ -86,11 +102,11 @@ public function queue(Pool $pool, Tuple $tuple): void
86102 foreach ($ this ->outerKeys as $ i => $ outerKey ) {
87103 $ state ->register ($ this ->innerKeys [$ i ], $ scope [$ outerKey ]);
88104 }
89- $ state ->setRelationStatus ($ this -> getName () , RelationInterface::STATUS_RESOLVED );
105+ $ state ->setRelationStatus ($ relName , RelationInterface::STATUS_RESOLVED );
90106 return ;
91107 }
92108 if ($ tuple ->status >= Tuple::STATUS_WAITED ) {
93- $ state ->setRelationStatus ($ this -> getName () , RelationInterface::STATUS_RESOLVED );
109+ $ state ->setRelationStatus ($ relName , RelationInterface::STATUS_RESOLVED );
94110 }
95111 return ;
96112 }
@@ -99,8 +115,8 @@ public function queue(Pool $pool, Tuple $tuple): void
99115
100116 if ($ this ->shouldPull ($ tuple , $ rTuple )) {
101117 $ this ->pullValues ($ state , $ rTuple ->state );
102- $ state ->setRelation ($ this -> getName () , $ related );
103- $ state ->setRelationStatus ($ this -> getName () , RelationInterface::STATUS_RESOLVED );
118+ $ state ->setRelation ($ relName , $ related );
119+ $ state ->setRelationStatus ($ relName , RelationInterface::STATUS_RESOLVED );
104120 }
105121 }
106122
0 commit comments