This repository was archived by the owner on Jun 1, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +8
-6
lines changed Expand file tree Collapse file tree 2 files changed +8
-6
lines changed Original file line number Diff line number Diff line change @@ -25,7 +25,9 @@ private function listGenerator($relations)
2525 {
2626 return (function ($ relations ) {
2727 foreach ($ relations as $ owner => $ related ) {
28- yield "$ owner/related " => ['json ' => ['resource ' => (array )$ related ]];
28+ foreach ($ related as $ r ) {
29+ yield "$ owner/related " => ['json ' => ['resource ' => [ 'id ' => $ r ['id ' ], 'type ' => $ r ['type ' ]]]];
30+ }
2931 }
3032 })($ relations );
3133 }
Original file line number Diff line number Diff line change @@ -77,16 +77,16 @@ public function createMany($entries)
7777
7878 $ results = $ this ->request ('post ' , $ this ->entriesJsonifier ($ entriesGenerator ($ entries )));
7979
80+ $ pwlinkedRelations = [];
81+
8082 foreach ($ results as $ result ) {
8183 if (!empty ($ relations [$ result ->custom_fields ['TM2 ID ' ]->getValue ()])) {
82- foreach ($ relations [$ result ->custom_fields ['TM2 ID ' ]->getValue ()] as $ relation ) {
83- if (!empty ($ relation ['id ' ])) {
84- $ this ->related ($ result ->id )->create ($ relation ['id ' ], $ relation ['type ' ]);
85- }
86- }
84+ $ pwlinkedRelations [$ result ->id ] = & $ relations [$ result ->custom_fields ['TM2 ID ' ]->getValue ()];
8785 }
8886 }
8987
88+ $ this ->relatedBatch ()->create ($ pwlinkedRelations );
89+
9090 return $ results ;
9191 }
9292
You can’t perform that action at this time.
0 commit comments