Closed barbeember closed 2 years ago
Hi gang,
I'm not finding in the documentation the syntax to order by a MapField property.
In the test below, how would I order by 'field1' or 'field2'? I tried using the firestore syntax of map_field_name.key, but this doesn't seem to work.
TIA!
Test code:
class Test(Model): name = fo.fields.TextField() score_data = fo.fields.MapField(default={ 'field1': 0, 'field2': 0 }) test1 = Test(name='test1') test1.save() test1.score_data['field1'] = 100 test1.score_data['field2'] = 300 test1.upsert() test2 = Test(name='test2') test2.save() test2.score_data['field1'] = 200 test2.score_data['field2'] = 200 test2.upsert() test3 = Test(name='test3') test3.save() test3.score_data['field1'] = 300 test3.score_data['field2'] = 100 test3.upsert() query = Test.collection.order('score_data.field2').fetch() for test in query: field1 = test.score_data['field1'] field2 = test.score_data['field2'] print(f"{test.name} - field1:{field1} field2:{field2}")
Output:
fireo.fields.errors.FieldNotFound: Field "score_data.field2" not found in model "Test"
In the Firestore UI, it works to orderBy("score_data.field1", "desc")
Fixed, update Fireo to 1.5.1
1.5.1
Hi gang,
I'm not finding in the documentation the syntax to order by a MapField property.
In the test below, how would I order by 'field1' or 'field2'? I tried using the firestore syntax of map_field_name.key, but this doesn't seem to work.
TIA!
Test code:
Output: