FirebaseExtended / firestoreodm-flutter

BSD 3-Clause "New" or "Revised" License
33 stars 9 forks source link

Preserving @Id Decorated Field while Using cloud_firestore_odm #23

Open Lyokone opened 2 weeks ago

Lyokone commented 2 weeks ago

copied from https://github.com/firebase/flutterfire/issues/11939

Hello Flutterfire Community,

I am currently working on a project that extensively uses cloud_firestore_odm, and have come across a scenario wherein I would like to keep the field decorated with @id in the Firestore document data.

The issue arises with the generated code:

static Map<String, Object?> toFirestore( User value, SetOptions? options, ) { return {...value.toJson()}..remove('uid'); } Here, the uid field, which is the @id decorated in my case, is consistently removed with every document update.

Upon referring to the Firestore documentation, it becomes evident that the @id field is not included in the Firestore object when encoded, by default. However, my requirement contradicts this default behavior, and I would like to preserve the @id field.

Could anyone guide me on how to stop cloud_firestore_odm from removing the uid field, which is marked with @id annotation, when encoding a Document? Any input on this would be greatly appreciated.

Thanks in advance for your help.