docs added Pivot include to doc examples

This commit is contained in:
silverqx
2021-11-13 14:09:38 +01:00
parent 794cacdd56
commit e56a28c1bf
2 changed files with 8 additions and 12 deletions

View File

@@ -410,6 +410,7 @@ Many-to-many relationships are defined by writing a method that returns the resu
#define USER_H
#include <orm/tiny/model.hpp>
#include <orm/tiny/relations/pivot.hpp>
#include "models/role.hpp"
@@ -474,13 +475,14 @@ To define the "inverse" of a many-to-many relationship, you should define a meth
#define ROLE_H
#include <orm/tiny/model.hpp>
class User; // Forward declaration to avoid cyclic dependency
#include <orm/tiny/relations/pivot.hpp>
using Orm::Tiny::Model;
using Orm::Tiny::Relations::BelongsToMany;
using Orm::Tiny::Relations::Pivot;
class User; // Forward declaration to avoid cyclic dependency
class Role final : public Model<Role, User, Pivot>
{
friend Model;
@@ -525,8 +527,6 @@ Notice that each `Role` model we retrieve has automatically assigned a `pivot` r
By default, only the model keys will be present on the `pivot` model. If your intermediate table contains extra attributes, you must specify them when defining the relationship:
using Orm::Tiny::Relations::BelongsToMany;
// Ownership of a unique_ptr()
auto relation = belongsToMany<Role>();
@@ -536,8 +536,6 @@ By default, only the model keys will be present on the `pivot` model. If your in
If you would like your intermediate table to have `created_at` and `updated_at` timestamps that are automatically maintained by TinyORM, call the `withTimestamps` method when defining the relationship:
using Orm::Tiny::Relations::BelongsToMany;
// Ownership of a unique_ptr()
auto relation = belongsToMany<Role>();
@@ -555,8 +553,6 @@ As noted previously, attributes from the intermediate table may be accessed on m
For example, if your application contains users that may subscribe to podcasts, you likely have a many-to-many relationship between users and podcasts. If this is the case, you may wish to rename your intermediate table relation name to `subscription` instead of `pivot`. This can be done using the `as` method when defining the relationship:
using Orm::Tiny::Relations::BelongsToMany;
// Ownership of a unique_ptr()
auto relation = belongsToMany<Podcast>();
@@ -590,6 +586,7 @@ Custom many-to-many pivot models should extend the `Orm::Tiny::Relations::BasePi
#define USER_H
#include <orm/tiny/model.hpp>
#include <orm/tiny/relations/pivot.hpp>
#include "models/role.hpp"
@@ -645,13 +642,12 @@ You have to pass a custom pivot type to the `AllRelations` template parameter pa
#include <orm/tiny/model.hpp>
class User; // Forward declaration to avoid cyclic dependency
#include "models/roleuser.hpp"
using Orm::Tiny::Model;
using Orm::Tiny::Relations::BelongsToMany;
using Orm::Tiny::Relations::Pivot;
class User; // Forward declaration to avoid cyclic dependency
class Role final : public Model<Role, User, RoleUser>
{

View File

@@ -125,7 +125,7 @@ namespace Relations {
// CUR check Caught expected exception with message in tinyplay silverqx
// CUR study how to use acquire/release memory order for m_queryLogId atomic silverqx
// CUR rename m_db to m_dm in tinyplay silverqx
// CUR docs pivot/basepivot include in examples silverqx
// CUR docs create empty project to test docs examples, I need to test many-to-many examples, I did some changes in docs silverqx
/*! Base model class. */
template<typename Derived, AllRelationsConcept ...AllRelations>
class Model :