@@ -66,7 +66,6 @@ public function compileInsert($query, array $values): array
6666
6767 // Prepare main document operation options
6868 $ options = [];
69- $ opType = null ;
7069
7170 // Handle routing
7271 if (isset ($ doc ['_routing ' ])) {
@@ -84,18 +83,6 @@ public function compileInsert($query, array $values): array
8483 unset($ doc ['_parent ' ]);
8584 }
8685
87- // Respect explicit op_type selection from document
88- if (isset ($ doc ['_op_type ' ])) {
89- $ opType = $ doc ['_op_type ' ];
90- unset($ doc ['_op_type ' ]);
91- } elseif (isset ($ doc ['op_type ' ])) {
92- $ opType = $ doc ['op_type ' ];
93- unset($ doc ['op_type ' ]);
94- } else {
95- // Also allow query option to drive op type
96- $ opType = $ query ->getOption ('insert_op_type ' , null );
97- }
98-
9986 // We don't want to save the ID as part of the doc
10087 // Unless the Model has explicitly set 'storeIdsInDocument'
10188 if ($ query ->getOption ('store_ids_in_document ' , false )) {
@@ -104,21 +91,19 @@ public function compileInsert($query, array $values): array
10491 } else {
10592 unset($ doc ['id ' ], $ doc ['_id ' ]);
10693 }
107-
108- // Add the document operation (index or create)
109- if ($ opType && strtolower ((string ) $ opType ) === 'create ' ) {
110- $ index = DslFactory::createOperation (
111- index: $ query ->getFrom (),
112- id: $ docId ,
113- options: $ options
114- );
115- } else {
116- $ index = DslFactory::indexOperation (
117- index: $ query ->getFrom (),
118- id: $ docId ,
119- options: $ options
120- );
94+ if (! empty ($ doc ['_op_type ' ])) {
95+ $ options ['op_type ' ] = $ doc ['_op_type ' ];
96+ unset($ doc ['_op_type ' ]);
97+ } elseif ($ optType = $ query ->getOption ('op_type ' )) {
98+ $ options ['op_type ' ] = $ optType ;
12199 }
100+
101+ // Add the document operation
102+ $ index = DslFactory::indexOperation (
103+ index: $ query ->getFrom (),
104+ id: $ docId ,
105+ options: $ options
106+ );
122107 $ dsl ->appendBody ($ index );
123108
124109 // Process document properties to ensure proper formatting
0 commit comments