From bbdee2e7d86524bb8fffd6280b8c4c2f21785d67 Mon Sep 17 00:00:00 2001 From: silverqx Date: Thu, 1 Sep 2022 17:11:00 +0200 Subject: [PATCH] docs note about u_xyz data member on Custom Pivots [skip ci] --- docs/tinyorm/relationships.mdx | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/docs/tinyorm/relationships.mdx b/docs/tinyorm/relationships.mdx index 9a58b1b4f..5de197ef0 100644 --- a/docs/tinyorm/relationships.mdx +++ b/docs/tinyorm/relationships.mdx @@ -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.