RefParam constructor

const RefParam(
  1. Type documentType, {
  2. Object? adapter,
})

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.

CollectionModelPathDocumentModelPathの各フィールドを指定する際に他のドキュメントを参照するときにフィールドに指定することでその参照ドキュメントを合わせてロードすることができます。

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});