Skip to content

Commit 7adff06

Browse files
Fenix: Fix firestore_document and document changes (#282)
Co-authored-by: Kyle Szklenski <[email protected]>
1 parent 344cc95 commit 7adff06

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

addons/godot-firebase/firestore/firestore_document.gd

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,26 @@ func _init(doc : Dictionary = {}, _doc_name : String = "", _doc_fields : Diction
2525
self.create_time = doc.createTime
2626

2727
# Pass a dictionary { 'key' : 'value' } to format it in a APIs usable .fields
28+
# Field Path using the "dot" (`.`) notation are supported:
29+
# ex. { "PATH.TO.SUBKEY" : "VALUE" } ==> { "PATH" : { "TO" : { "SUBKEY" : "VALUE" } } }
2830
static func dict2fields(dict : Dictionary) -> Dictionary:
2931
var fields : Dictionary = {}
3032
var var_type : String = ""
3133
for field in dict.keys():
3234
var field_value = dict[field]
33-
match typeof(dict[field]):
35+
if "." in field:
36+
var keys: Array = field.split(".")
37+
field = keys.pop_front()
38+
keys.invert()
39+
for key in keys:
40+
field_value = { key : field_value }
41+
match typeof(field_value):
3442
TYPE_NIL: var_type = "nullValue"
3543
TYPE_BOOL: var_type = "booleanValue"
3644
TYPE_INT: var_type = "integerValue"
3745
TYPE_REAL: var_type = "doubleValue"
3846
TYPE_STRING: var_type = "stringValue"
39-
TYPE_DICTIONARY:
47+
TYPE_DICTIONARY:
4048
if is_field_timestamp(field_value):
4149
var_type = "timestampValue"
4250
field_value = dict2timestamp(field_value)

0 commit comments

Comments
 (0)