@@ -66,7 +66,6 @@ public function compileInsert($query, array $values): array
66
66
67
67
// Prepare main document operation options
68
68
$ options = [];
69
- $ opType = null ;
70
69
71
70
// Handle routing
72
71
if (isset ($ doc ['_routing ' ])) {
@@ -84,18 +83,6 @@ public function compileInsert($query, array $values): array
84
83
unset($ doc ['_parent ' ]);
85
84
}
86
85
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
-
99
86
// We don't want to save the ID as part of the doc
100
87
// Unless the Model has explicitly set 'storeIdsInDocument'
101
88
if ($ query ->getOption ('store_ids_in_document ' , false )) {
@@ -104,21 +91,19 @@ public function compileInsert($query, array $values): array
104
91
} else {
105
92
unset($ doc ['id ' ], $ doc ['_id ' ]);
106
93
}
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 ;
121
99
}
100
+
101
+ // Add the document operation
102
+ $ index = DslFactory::indexOperation (
103
+ index: $ query ->getFrom (),
104
+ id: $ docId ,
105
+ options: $ options
106
+ );
122
107
$ dsl ->appendBody ($ index );
123
108
124
109
// Process document properties to ensure proper formatting
0 commit comments