flutterfire icon indicating copy to clipboard operation
flutterfire copied to clipboard

🐛 [ODM] generated orderBy methods do not support aliases

Open AgDude opened this issue 2 years ago • 1 comments

Bug report

Describe the bug When the name is defined in the JsonKey for a field that has a different name on the class and in the field in cloud firestore the generated orderBy methods return no results.

Steps to reproduce

Steps to reproduce the behavior:

Define a model with a aliased name

class MyModel{
  MyModel({
    this.name,
    this.displayOrder,
  })

  @JsonKey()
  string name;

  @JsonKey(name: 'display_order')
  int displayOrder;
}

Notice that in the generated orderByDisplayOrder method on the MyModelQuery class the query line is var query = reference.orderBy('displayOrder', descending: false); This causes zero documents to be returned when using the ordering method.

Expected behavior

It is expected that the the query is var query = reference.orderBy('display_order', descending: false);, using the name from the JsonKey annoatation.

AgDude avatar Dec 29 '21 13:12 AgDude

Renaming properties is not supported at the moment.

rrousselGit avatar Dec 29 '21 14:12 rrousselGit

This should have been closed before. Renaming is supported now, although it requires enabling a specific json_serializable flag (createFieldMap)

So closing

rrousselGit avatar Oct 24 '22 09:10 rrousselGit