RefParam constructor
When specifying a CollectionModelPath or DocumentModelPath field, you can load the referenced document together by specifying it in the field when referencing other documents.
Define the class of the document by specifying documentType.
When adapter is specified, you can specify the ModelAdapter of the data to be read.
Use with freezed
, etc.
If this field is present, a ModelRefMixin
is automatically assigned to the document.
CollectionModelPathやDocumentModelPathの各フィールドを指定する際に他のドキュメントを参照するときにフィールドに指定することでその参照ドキュメントを合わせてロードすることができます。
documentTypeを指定してドキュメントのクラスを定義します。
adapterを指定すると、読み込むデータのModelAdapterを指定することができます。
freezed
などと共に利用してください。
このフィールドが存在する場合は、ドキュメントにModelRefMixin
が自動で付与されます。
@freezed
@formValue
@immutable
@CollectionModelPath("shop")
class ShopModel with _$ShopModel {
const factory ShopModel({
@Default("") String name,
@Default("") String description,
@RefParam(UserModelDocument) ModelRef<UserModel> user,
}) = _ShopModel;
const ShopModel._();
factory ShopModel.fromJson(Map<String, Object?> json) => _$ShopModelFromJson(json);
static const document = _$ShopModelDocumentQuery();
static const collection = _$ShopModelCollectionQuery();
}
Implementation
const RefParam(this.documentType, {this.adapter});