Skip to content

Commit 3c57497

Browse files
committed
PHPC-245: Allow embedding objects in updates
1 parent e147fd3 commit 3c57497

File tree

4 files changed

+6
-5
lines changed

4 files changed

+6
-5
lines changed

php_bson.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ typedef enum {
3434
PHONGO_BSON_ADD_ID = 0x01,
3535
PHONGO_BSON_RETURN_ID = 0x02,
3636
PHONGO_BSON_ADD_ODS = 0x04,
37+
PHONGO_BSON_ADD_CHILD_ODS = 0x08
3738
} phongo_bson_flags_t;
3839

3940
PHONGO_API void zval_to_bson(zval *data, phongo_bson_flags_t flags, bson_t *bson, bson_t **bson_out TSRMLS_DC);

src/MongoDB/BulkWrite.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ PHP_METHOD(BulkWrite, insert)
9797
if (return_value_used) {
9898
bson_flags |= PHONGO_BSON_RETURN_ID;
9999
}
100-
bson_flags |= PHONGO_BSON_ADD_ODS;
100+
bson_flags |= PHONGO_BSON_ADD_ODS|PHONGO_BSON_ADD_CHILD_ODS;
101101

102102
bson = bson_new();
103103
zval_to_bson(document, bson_flags, bson, &bson_out TSRMLS_CC);

src/MongoDB/Manager.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ PHP_METHOD(Manager, executeInsert)
172172

173173

174174
bson = bson_new();
175-
zval_to_bson(document, PHONGO_BSON_ADD_ODS, bson, NULL TSRMLS_CC);
175+
zval_to_bson(document, PHONGO_BSON_ADD_ODS|PHONGO_BSON_ADD_CHILD_ODS, bson, NULL TSRMLS_CC);
176176
phongo_execute_single_insert(intern->client, namespace, bson, phongo_write_concern_from_zval(zwrite_concern TSRMLS_CC), -1, return_value, return_value_used TSRMLS_CC);
177177
bson_clear(&bson);
178178
}
@@ -204,7 +204,7 @@ PHP_METHOD(Manager, executeUpdate)
204204
query = bson_new();
205205
update = bson_new();
206206
zval_to_bson(zquery, PHONGO_BSON_NONE, query, NULL TSRMLS_CC);
207-
zval_to_bson(newObj, PHONGO_BSON_NONE, update, NULL TSRMLS_CC);
207+
zval_to_bson(newObj, PHONGO_BSON_ADD_CHILD_ODS, update, NULL TSRMLS_CC);
208208

209209
if (updateOptions) {
210210
flags |= php_array_fetch_bool(updateOptions, "multi") ? MONGOC_UPDATE_MULTI_UPDATE : 0 ;

src/bson.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ void object_to_bson(zval *object, phongo_bson_flags_t flags, const char *key, lo
591591

592592
bson_append_document_begin(bson, key, key_len, &child);
593593
if (instanceof_function(Z_OBJCE_P(object), php_phongo_persistable_ce TSRMLS_CC)) {
594-
if (flags & PHONGO_BSON_ADD_ODS) {
594+
if (flags & PHONGO_BSON_ADD_CHILD_ODS) {
595595
bson_append_binary(&child, PHONGO_ODM_FIELD_NAME, -1, 0x80, (const uint8_t *)Z_OBJCE_P(object)->name, strlen(Z_OBJCE_P(object)->name));
596596
}
597597
}
@@ -889,7 +889,7 @@ PHP_FUNCTION(fromArray)
889889
}
890890

891891
bson = bson_new();
892-
zval_to_bson(data, PHONGO_BSON_ADD_ODS, bson, NULL TSRMLS_CC);
892+
zval_to_bson(data, PHONGO_BSON_ADD_ODS|PHONGO_BSON_ADD_CHILD_ODS, bson, NULL TSRMLS_CC);
893893

894894
RETVAL_STRINGL((const char *) bson_get_data(bson), bson->len, 1);
895895
bson_destroy(bson);

0 commit comments

Comments
 (0)