ModelRefMapBuilder<TSource, TResult> constructor

const ModelRefMapBuilder<TSource, TResult>({
  1. required Map<String, ModelRefBase?>? modelRef(
    1. TSource value
    ),
  2. required ModelRefMixin<TResult> document(
    1. DocumentModelQuery modelQuery
    ),
  3. required TSource value(
    1. TSource value,
    2. Map<String, ModelRefMixin<TResult>> documents
    ),
  4. ModelAdapter? adapter,
  5. ModelAccessQuery? accessQuery,
  6. List<ModelValidationQuery>? validationQueries,
})

Builder for granting relationships between models and loading data.

The map in ModelRef is processed. The keys of the map are inherited as is.

Define ModelRefLoaderMixin to match the mix-in.

The procedure is;

  1. Returns a map of ModelRefBase containing only the relation information stored in TSource via modelRef.
  2. Generates and returns a mixed-in DocumentBase with ModelRefMixin<TResult> based on DocumentModelQuery via document.
  3. Save the map of DocumentBase generated via value to TSource and return an updated TSource.

モデル間のリレーションを付与しデータのロードを行うためのビルダー。

ModelRefのマップを処理します。マップのキーはそのまま引き継がれます。

ModelRefLoaderMixinをミックスインしたときに合わせて定義します。

手順としては

  1. TSourceに保存されているリレーション情報のみ入ったModelRefBaseのマップをmodelRef経由で返します。
  2. DocumentModelQueryを元にModelRefMixin<TResult>をミックスインしたDocumentBasedocument経由で生成し返します。
  3. value経由で生成されたDocumentBaseのマップをTSourceに保存して、更新したTSourceを返すようにします。
@override
List<ModelRefBuilderBase<StreamModel>> get builder => [
      ModelRefMapBuilder(
        modelRef: (value) => value.userMap,
        document: (query) => UserModelDocument(query),
        value: (value, documents) {
          return value.copyWith(userMap: documents);
        },
      )
    ];

Implementation

const ModelRefMapBuilder({
  required this.modelRef,
  required this.document,
  required this.value,
  this.adapter,
  this.accessQuery,
  this.validationQueries,
});