From 9aae5549ac91cb44a47515baaf0e2fa21036e14c Mon Sep 17 00:00:00 2001 From: silverqx Date: Wed, 31 Aug 2022 20:33:16 +0200 Subject: [PATCH] docs added SoftDeletes caution [skip ci] --- docs/tinyorm/relationships.mdx | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/docs/tinyorm/relationships.mdx b/docs/tinyorm/relationships.mdx index 70c1974e3..9a58b1b4f 100644 --- a/docs/tinyorm/relationships.mdx +++ b/docs/tinyorm/relationships.mdx @@ -697,7 +697,18 @@ Once the custom pivot model `RoleUser` has been defined, `getRelation` or `getRe qDebug() << role->getRelation("pivot") ->getAttribute("created_at"); -##### Closer Look To Defining Custom Intermediate Table Models +:::caution +Custom Pivot models may not use the `SoftDeletes` base class. If you need to soft delete pivot records consider converting your pivot model to an actual TinyORM model. +::: + +#### Custom Pivot Models And Incrementing IDs + +If you have defined a many-to-many relationship that uses a custom pivot model, and that pivot model has an auto-incrementing primary key, you should ensure your custom pivot model class defines an `u_incrementing` data member that is set to `true`. + + /*! Indicates if the IDs are auto-incrementing. */ + bool u_incrementing = true; + +#### Closer Look At Defining Custom Intermediate Table Models I can tell that defining a custom intermediate table models is the most confusing part of the TinyORM framework, let's look closer at it. @@ -709,13 +720,6 @@ The same is true for the basic `Pivot` model, if you are using a basic pivot mod The reason for all of this is so that the `Model` knows how to generate a `std::variant` to hold the pivot model in the `Model::m_relations` data member hash map, which you get using the `Model::getRelationValue` or `Model::getRelation` methods. -#### Custom Pivot Models And Incrementing IDs - -If you have defined a many-to-many relationship that uses a custom pivot model, and that pivot model has an auto-incrementing primary key, you should ensure your custom pivot model class defines an `u_incrementing` data member that is set to `true`. - - /*! Indicates if the IDs are auto-incrementing. */ - bool u_incrementing = true; - ## Querying Relations Since all TinyORM relationships are defined via methods, you may call those methods to obtain an instance of the relationship without actually executing a query to load the related models. In addition, all types of TinyORM relationships also serve as [query builders](database/query-builder.mdx), allowing you to continue to chain constraints onto the relationship query before finally executing the SQL query against your database.