Skip to content

Commit

Permalink
docs added SoftDeletes caution
Browse files Browse the repository at this point in the history
[skip ci]
  • Loading branch information
silverqx committed Aug 31, 2022
1 parent 490b93e commit 9aae554
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions docs/tinyorm/relationships.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,18 @@ Once the custom pivot model `RoleUser` has been defined, `getRelation` or `getRe
qDebug() << role->getRelation<RoleUser, Orm::One>("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.

Expand All @@ -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.
Expand Down

0 comments on commit 9aae554

Please sign in to comment.