28class QELOQUENT_EXPORT
Model :
public Entity,
41 QVariant primary()
const;
42 void setPrimary(
const QVariant &value);
44 QVariant property(
const QString &name)
const;
45 void setProperty(
const QString &name,
const QVariant &value);
47 QVariant label()
const;
49 QVariant field(
const QString &name)
const;
50 void setField(
const QString &name,
const QVariant &value);
52 bool exists()
override final;
53 bool get()
override final;
54 bool insert()
override final;
55 bool update()
override final;
56 bool deleteData()
override final;
58 bool load(
const QString &relation);
59 bool load(
const QStringList &relations);
61 Query lastQuery()
const;
62 Error lastError()
const;
64 MetaObject metaObject()
const;
67 QString serializationContext()
const override final;
68 bool isListSerializable()
const override final;
69 QList<DataMap> serialize()
const override final;
70 void deserialize(
const QList<DataMap> &data,
bool all =
false)
override final;
72 DataMap fullDataMap()
const;
75 template<typename T, std::enable_if<std::is_base_of<Model, T>::value>::type* =
nullptr>
Model(T *self);
76 Model(
const QMetaObject &metaObject);
77 Model(ModelData *data);
79 QDateTime now()
const;
82 Relation<T> hasOne(
const QString &foreignKey = QString(),
const QString &localKey = QString(),
83 const std::source_location &location = std::source_location::current())
const;
86 Relation<T> hasMany(
const QString &foreignKey = QString(),
const QString &localKey = QString(),
87 const std::source_location &location = std::source_location::current())
const;
89 template<
typename T,
typename Through>
90 Relation<T> hasManyThrough(
const QString &foreignKey = QString(),
const QString &localKey = QString(),
91 const QString &throughForeignKey = QString(),
const QString &throughLocalKey = QString(),
92 const std::source_location &location = std::source_location::current())
const;
95 Relation<T> belongsTo(
const QString &foreignKey = QString(),
const QString &ownerKey = QString(),
96 const std::source_location &location = std::source_location::current())
const;
99 Relation<T> belongsToMany(
const QString &table = QString(),
const QString &foreignPivotKey = QString(),
100 const QString &relatedPivotKey = QString(),
const QString &parentKey = QString(),
101 const QString &relatedKey = QString(),
102 const std::source_location &location = std::source_location::current())
const;
104 template<
typename T,
typename Through>
105 Relation<T> belongsToManyThrough(
const QString &table = QString(),
const QString &foreignPivotKey = QString(),
106 const QString &relatedPivotKey = QString(),
const QString &parentKey = QString(),
107 const QString &relatedKey = QString(),
108 const std::source_location &location = std::source_location::current())
const;
110 QSharedDataPointer<ModelData> data;
113 Query newQuery(
const std::function<QString (
const Query &)> &statementGenerator,
bool filter)
const;
114 Result<::QSqlQuery, QSqlError> exec(
const std::function<QString (
const Query &)> &statementGenerator,
bool filter);
116 friend class MetaObject;
117 friend class MetaProperty;
118 friend class RelationData;
179 const QString &throughForeignKey,
const QString &throughLocalKey,
const std::source_location &location)
const
182 auto d =
new HasManyThroughRelationData<T, Through>();
183 d->foreignKey = foreignKey;
184 d->localKey = localKey;
185 d->throughForeignKey = throughForeignKey;
186 d->throughLocalKey = throughLocalKey;
221 const QString &relatedPivotKey,
const QString &parentKey,
222 const QString &relatedKey,
const std::source_location &location)
const
225 auto d =
new BelongsToManyRelationData<T>();
227 d->foreignPivotKey = foreignPivotKey;
228 d->relatedPivotKey = relatedPivotKey;
229 d->parentKey = parentKey;
230 d->relatedKey = relatedKey;
246 const QString &relatedPivotKey,
const QString &parentKey,
247 const QString &relatedKey,
const std::source_location &location)
const
250 auto d =
new BelongsToManyThroughRelationData<T, Through>();
252 d->foreignPivotKey = foreignPivotKey;
253 d->relatedPivotKey = relatedPivotKey;
254 d->parentKey = parentKey;
255 d->relatedKey = relatedKey;
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.
Definition model.h:158
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.
Definition model.h:245
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.
Definition model.h:178
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.
Definition model.h:139
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.
Definition model.h:200
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.
Definition model.h:220