flutterfire icon indicating copy to clipboard operation
flutterfire copied to clipboard

[ODM] Add support for document reference

Open rrousselGit opened this issue 3 years ago • 3 comments

Add a @Document(path)

Originally posted by @CiriousJoker in https://github.com/FirebaseExtended/flutterfire/discussions/7475#discussioncomment-1795752

rrousselGit avatar Dec 13 '21 10:12 rrousselGit

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!

AirborneEagle avatar Dec 17 '21 18:12 AirborneEagle

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 @Collection annotation. 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 avatar Dec 17 '21 22:12 AirborneEagle

@AirborneEagle this issue is unrelated to properties of type Reference

rrousselGit avatar Dec 19 '21 12:12 rrousselGit