Skip to content

Commit

Permalink
docs note about u_xyz data member on Custom Pivots
Browse files Browse the repository at this point in the history
[skip ci]
  • Loading branch information
silverqx committed Sep 1, 2022
1 parent 66d5635 commit bbdee2e
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions docs/tinyorm/relationships.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,18 @@ 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.

##### User Data Members on Custom Intermediate Table Models

This is another nonstandard part of the custom pivot models. The `u_connection` and `u_timestamps` user data members and the `CREATED_AT` and `UPDATED_AT` static data members are ignored when obtaining pivot records from the database during the lazy or eager loading.

Let's describe how these data members are resolved:

- `u_connection` - inferred from the parent model
- `u_timestamps` - true if obtained attributes contain both the `CREATED_AT` and `UPDATED_AT` attributes
- `CREATED_AT`, `UPDATED_AT` - inferred from the parent model, can be overridden using the `withTimestamps()` method

All these data members are taken into account normally when you call the `create`, `save`, `update`, ... on the Custom Pivot models!

## 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 bbdee2e

Please sign in to comment.