From 6bb85fae76d4588ab187a2015dd5c2808fb71718 Mon Sep 17 00:00:00 2001 From: silverqx Date: Sat, 24 Jun 2023 19:58:26 +0200 Subject: [PATCH] docs added missing collection methods Added documentation for all, toBase, toJson, toJsonArray, toJsonDocument, toMap, toMapVariantList, toVector, and toVectorVariantList. --- docs/tinyorm/collections.mdx | 81 +++++++++++++++++++++++++++++++++++- 1 file changed, 80 insertions(+), 1 deletion(-) diff --git a/docs/tinyorm/collections.mdx b/docs/tinyorm/collections.mdx index 805ee8f30..67d0c1c5b 100644 --- a/docs/tinyorm/collections.mdx +++ b/docs/tinyorm/collections.mdx @@ -96,6 +96,7 @@ Furthermore, almost every method returns a new `ModelsCollection` instance, allo
+[all](#method-all) [contains](#method-contains) [doesntContain](#method-doesntcontain) [each](#method-each) @@ -126,7 +127,15 @@ Furthermore, almost every method returns a new `ModelsCollection` instance, allo [stableSortByDesc](#method-stablesortbydesc) [stableSortDesc](#method-stablesortdesc) [tap](#method-tap) +[toBase](#method-tobase) +[toJson](#method-tojson) +[toJsonArray](#method-tojsonarray) +[toJsonDocument](#method-tojsondocument) +[toMap](#method-tomap) +[toMapVariantList](#method-tomapvariantlist) [toQuery](#method-toquery) +[toVector](#method-tovector) +[toVectorVariantList](#method-tovectorvariantlist) [unique](#method-unique) [uniqueBy](#method-uniqueby) [uniqueRelaxed](#method-uniquerelaxed) @@ -148,6 +157,16 @@ For a better understanding of the following examples, many of the variable decla
+#### `all()` {#method-all} + +The `all` method returns a copy of the underlying vector represented by the collection: + + QVector = users.all(); + +:::note +The [`toBase`](#method-tobase) is an alias to the `all` method. +::: + #### `contains()` {#method-contains} The `contains` method may be used to determine if a given model instance is contained by the collection. This method accepts a primary key or a model instance: @@ -789,9 +808,53 @@ The `tap` method returns an lvalue __reference__ to the currently processed coll It can be also called on `ModelsCollection` rvalues, it returns an rvalue reference in this case. +#### `toBase()` {#method-tobase} + +The `toBase` method returns a copy of the underlying vector represented by the collection: + + QVector = users.toBase(); + +:::note +The [`toBase`](#method-tobase) is an alias to the `all` method. +::: + +#### `toJson()` {#method-tojson} + +The `toJson` method converts the collection of models with all nested relations into a JSON serialized `QByteArray`. + +It returns an empty array for empty `many` type relations and `null` for empty `one` type relations. + +:::info +The `toJson` method accepts the [`QJsonDocument::JsonFormat`](https://doc.qt.io/qt-6/qjsondocument.html#JsonFormat-enum), possible values are `QJsonDocument::Indented` or `QJsonDocument::Compact`. +::: + +#### `toJsonArray()` {#method-tojsonarray} + +The `toJsonArray` method converts the collection of models with all nested relations into a [`QJsonArray`](https://doc.qt.io/qt-6/qjsonarray.html). + +#### `toJsonDocument()` {#method-tojsondocument} + +The `toJsonDocument` method converts the collection of models with all nested relations into a [`QJsonDocument`](https://doc.qt.io/qt-6/qjsondocument.html). + +#### `toMap()` {#method-tomap} + +The `toMap` method converts the collection of models with all nested relations into an attributes map `QVector`. + +It returns an empty `QVariantList` for empty `many` type relations and a null `QVariant` for empty `one` type relations. + +#### `toMapVariantList()` {#method-tomapvariantlist} + +The `toMapVariantList` method converts the collection of models with all nested relations into an attributes map, but it returns the `QVariantList` instead of the `QVector`. + +It returns an empty `QVariantList` for empty `many` type relations and a null `QVariant` for empty `one` type relations. + +:::note +The `toMapVariantList` method is internally needed by the `toJson` related methods. +::: + #### `toQuery()` {#method-toquery} -The `toQuery` method returns the `TinyBuilder` instance containing a `whereIn` constraint with the collection models' primary keys: +The `toQuery` method returns the `TinyBuilder` instance containing a `whereIn` constraint with the collection of models' primary keys: using Models::User; @@ -801,6 +864,22 @@ The `toQuery` method returns the `TinyBuilder` instance containing a `whereIn` c {"status", "Administrator"}, }); +#### `toVector()` {#method-tovector} + +The `toVector` method converts the collection of models with all nested relations into an attributes vector `QVector>`. + +It returns an empty `QVariantList` for empty `many` type relations and a null `QVariant` for empty `one` type relations. + +#### `toVectorVariantList()` {#method-tovectorvariantlist} + +The `toVectorVariantList` method converts the collection of models with all nested relations into an attributes vector, but it returns the `QVariantList` instead of the `QVector>`. + +It returns an empty `QVariantList` for empty `many` type relations and a null `QVariant` for empty `one` type relations. + +:::note +The `toVectorVariantList` method is internally needed by the `toJson` related methods. +::: + #### `unique()` {#method-unique} The `unique` method returns all of the unique models in the __sorted__ collection. Any models with the same primary key as another model in the collection are removed: