QEloquent 1.1.0
Qt most flexible ORM.
Loading...
Searching...
No Matches
QEloquent::Model Class Reference

The Model class is the base class for all ORM models. More...

Inherits QEloquent::Entity, Serializable, and Deserializable.

Public Member Functions

 Model (const Model &)
 Copy constructor.
 
 Model (Model &&)
 Move constructor.
 
Modeloperator= (const Model &)
 Copy assignment operator.
 
Modeloperator= (Model &&)
 Move assignment operator.
 
virtual ~Model ()
 Virtual destructor.
 
QVariant primary () const
 Returns the value of the primary key.
 
void setPrimary (const QVariant &value)
 Sets the primary key value.
 
QVariant property (const QString &name) const
 Returns a property value by name.
 
void setProperty (const QString &name, const QVariant &value)
 Sets a property value by name.
 
bool exists () override final
 Returns true if the model exists in the database.
 
bool get () override final
 Refreshes the model data from the database.
 
bool insert () override final
 Inserts the model into the database.
 
bool update () override final
 Updates the model in the database.
 
bool deleteData () override final
 Deletes the model from the database.
 
bool load (const QString &relation)
 Eagerly loads a relationship.
 
bool load (const QStringList &relations)
 Eagerly loads multiple relationships.
 
Query lastQuery () const
 Returns the last query executed by this model.
 
Error lastError () const
 Returns the last error encountered by this model.
 
MetaObject metaObject () const
 Returns the metadata object for this model.
 
Connection connection () const
 Returns the database connection used by this model.
 

Protected Member Functions

template<typename T >
Relation< T > hasOne (const QString &foreignKey=QString(), const QString &localKey=QString(), const std::source_location &location=std::source_location::current()) const
 Defines a one-to-one relationship.
 
template<typename T >
Relation< T > hasMany (const QString &foreignKey=QString(), const QString &localKey=QString(), const std::source_location &location=std::source_location::current()) const
 Defines a one-to-many relationship.
 
template<typename T , typename Through >
Relation< T > hasManyThrough (const QString &foreignKey=QString(), const QString &localKey=QString(), const QString &throughForeignKey=QString(), const QString &throughLocalKey=QString(), const std::source_location &location=std::source_location::current()) const
 Defines a has-many-through relationship.
 
template<typename T >
Relation< T > belongsTo (const QString &foreignKey=QString(), const QString &ownerKey=QString(), const std::source_location &location=std::source_location::current()) const
 Defines an inverse one-to-one or many-to-one relationship.
 
template<typename T >
Relation< T > belongsToMany (const QString &table=QString(), const QString &foreignPivotKey=QString(), const QString &relatedPivotKey=QString(), const QString &parentKey=QString(), const QString &relatedKey=QString(), const std::source_location &location=std::source_location::current()) const
 Defines a many-to-many relationship.
 
template<typename T , typename Through >
Relation< T > belongsToManyThrough (const QString &table=QString(), const QString &foreignPivotKey=QString(), const QString &relatedPivotKey=QString(), const QString &parentKey=QString(), const QString &relatedKey=QString(), const std::source_location &location=std::source_location::current()) const
 Defines a belongs-to-many-through relationship.
 

Detailed Description

The Model class is the base class for all ORM models.

It provides the core functionality for attribute management, persistence, and relationship definition. Models are typically defined using Q_GADGET and Q_PROPERTY macros to enable reflection and database mapping.

Member Function Documentation

◆ hasOne()

template<typename T >
Relation< T > QEloquent::Model::hasOne ( const QString &  foreignKey = QString(),
const QString &  localKey = QString(),
const std::source_location &  location = std::source_location::current() 
) const
inlineprotected

Defines a one-to-one relationship.

Parameters
foreignKeyThe foreign key of the related model.
localKeyThe local key of the parent model.
locationThe source location, used to compute the function name to name relation.
Returns
A Relation object.

◆ hasMany()

template<typename T >
Relation< T > QEloquent::Model::hasMany ( const QString &  foreignKey = QString(),
const QString &  localKey = QString(),
const std::source_location &  location = std::source_location::current() 
) const
inlineprotected

Defines a one-to-many relationship.

Parameters
foreignKeyThe foreign key of the related model.
localKeyThe local key of the parent model.
locationThe source location, used to compute the function name to name relation.
Returns
A Relation object.

◆ hasManyThrough()

template<typename T , typename Through >
Relation< T > QEloquent::Model::hasManyThrough ( const QString &  foreignKey = QString(),
const QString &  localKey = QString(),
const QString &  throughForeignKey = QString(),
const QString &  throughLocalKey = QString(),
const std::source_location &  location = std::source_location::current() 
) const
inlineprotected

Defines a has-many-through relationship.

Parameters
foreignKeyThe foreign key of the intermediate model.
localKeyThe local key of the parent model.
throughForeignKeyThe foreignKey referenced on the through table
locationThe source location, used to compute the function name to name relation.
Returns
A Relation object.

◆ belongsTo()

template<typename T >
Relation< T > QEloquent::Model::belongsTo ( const QString &  foreignKey = QString(),
const QString &  ownerKey = QString(),
const std::source_location &  location = std::source_location::current() 
) const
inlineprotected

Defines an inverse one-to-one or many-to-one relationship.

Parameters
foreignKeyThe foreign key of the current model.
ownerKeyThe owner key of the related model.
locationThe source location, used to compute the function name to name relation.
Returns
A Relation object.

◆ belongsToMany()

template<typename T >
Relation< T > QEloquent::Model::belongsToMany ( const QString &  table = QString(),
const QString &  foreignPivotKey = QString(),
const QString &  relatedPivotKey = QString(),
const QString &  parentKey = QString(),
const QString &  relatedKey = QString(),
const std::source_location &  location = std::source_location::current() 
) const
inlineprotected

Defines a many-to-many relationship.

Parameters
tableThe pivot table name.
foreignPivotKeyThe foreign key of the current model in the pivot table.
relatedPivotKeyThe foreign key of the related model in the pivot table.
locationThe source location, used to compute the function name to name relation.
Returns
A Relation object.

◆ belongsToManyThrough()

template<typename T , typename Through >
Relation< T > QEloquent::Model::belongsToManyThrough ( const QString &  table = QString(),
const QString &  foreignPivotKey = QString(),
const QString &  relatedPivotKey = QString(),
const QString &  parentKey = QString(),
const QString &  relatedKey = QString(),
const std::source_location &  location = std::source_location::current() 
) const
inlineprotected

Defines a belongs-to-many-through relationship.

Parameters
tableThe pivot table name.
foreignPivotKeyThe foreign key of the intermediate model in the pivot table.
relatedPivotKeyThe foreign key of the related model in the pivot table.
locationThe source location, used to compute the function name to name relation.
Returns
A Relation object.

The documentation for this class was generated from the following files: