flutterfire
flutterfire copied to clipboard
[ODM] Add support for document reference
Add a @Document(path)
Originally posted by @CiriousJoker in https://github.com/FirebaseExtended/flutterfire/discussions/7475#discussioncomment-1795752
Hey. @rrousselGit I believe that this is a different use case, but I am looking for a solution for field type of Reference
As an example, a product document has a reference field called company
or an order that has multiple reference fields: user, product, company, etc.
How would I use firestore ODM to represent this? I don't really have any good ideas to solve this.
Thanks for helping!
Ok. Upon further reading, and use, I think I now understand, that this @Document(path) would in fact solve my problem exactly.
and that my solution would look something like this when @Document(path) is available:
if I have these top level collections, users, companies, products, purchases
where a purchase doc has many document references.
- doc ref to the user
- doc ref to the company
- an array of doc ref to many products. I assume this one may somehow use the
@Collectionannotation. but is that even possible yet?
@JsonSerializable()
class Purchase {
Purchase({
required this.price,
}) {
_$assertSubscription(this);
}
@Min(0)
final int price;
}
@Collection<Purchase>('purchases')
@Document<User>('users/*', name: 'user')
@Document<Company>('companies/*', name: 'company')
@Collection<Product>('products', name: 'products') // <- this one is am unsure of. How could we reference an array of References?
final moviesRef = MovieCollectionReference();
@AirborneEagle this issue is unrelated to properties of type Reference