ModelRefMapBuilder<TSource, TResult> constructor
const
ModelRefMapBuilder<TSource, TResult> ({
- required Map<
String, ModelRefBase?> ? modelRef(- TSource value
- required ModelRefMixin<
TResult> document(- DocumentModelQuery modelQuery
- required TSource value(
- TSource value,
- Map<
String, ModelRefMixin< documentsTResult> >
- ModelAdapter? adapter,
- ModelAccessQuery? accessQuery,
- 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;
- Returns a map of ModelRefBase containing only the relation information stored in
TSource
via modelRef. - Generates and returns a mixed-in DocumentBase with ModelRefMixin<TResult> based on DocumentModelQuery via document.
- Save the map of DocumentBase generated via value to
TSource
and return an updatedTSource
.
モデル間のリレーションを付与しデータのロードを行うためのビルダー。
ModelRefのマップを処理します。マップのキーはそのまま引き継がれます。
ModelRefLoaderMixinをミックスインしたときに合わせて定義します。
手順としては
TSource
に保存されているリレーション情報のみ入ったModelRefBaseのマップをmodelRef経由で返します。- DocumentModelQueryを元にModelRefMixin<TResult>をミックスインしたDocumentBaseをdocument経由で生成し返します。
- 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,
});