This template class describes Active Record relations.
You can find more information in comments below.
template
class TDbRelation :public virtual IDbRelation, public CReleasable
{
protected:
void LoadRelations(std::vector<CDbBaseActiveRecord *> &parent_models, std::vector<CDbBaseActiveRecord *> &out_models) override;
public:
TDbRelation( // Constructor representing One-to-One or One-to-Many relation
CDbBaseActiveRecord *parent,
const String &name,
const String &parent_attribute,
const String &relation_attribute,
const bool many = false);
TDbRelation( // Constructor representing Many-to-Many relation
CDbBaseActiveRecord *parent,
const String &name,
const String &parent_attribute,
const String &relation_attribute,
const String &link_table,
const String &link_parent_attribute,
const String &link_relation_attribute);
ReleasablePtr<Model> operator->(); // Return first model or nullptr if no models in list. Load models first if they were not loaded yet (lazy loading)
ReleasablePtr<Model> operator[](const size_t index); // Return model by index or nullptr if index out of bounds. Load models first if they were not loaded yet (lazy loading)
const ReleasablePtr<Model> operator[](const size_t index) const; // Return model by index or nullptr if index out of bounds. Load models first if they were not loaded yet (lazy loading)
typename std::vector<ReleasablePtr<Model>>::iterator begin(); // Return iterator pointing to the beginning. Load models first if they were not loaded yet (lazy loading)
typename std::vector<ReleasablePtr<Model>>::iterator end(); // Return iterator pointing to the end. Load models first if they were not loaded yet (lazy loading)
typename std::vector<ReleasablePtr<Model>>::reverse_iterator rbegin(); // Return reverse iterator pointing to the beginning. Load models first if they were not loaded yet (lazy loading)
typename std::vector<ReleasablePtr<Model>>::reverse_iterator rend(); // Return reverse iterator pointing to the end. Load models first if they were not loaded yet (lazy loading)
typename std::vector<ReleasablePtr<Model>>::size_type size(const bool load = true); // Return count of models. Load models first if they were not loaded yet (lazy loading)
bool empty(const bool load = true); // Return whether there are any models in list. Load models first if they were not loaded yet (lazy loading)
void push_back(ReleasablePtr<Model> model, const bool load = true); // Add new model to the list. Load models first if they were not loaded yet (lazy loading)
typename std::vector<ReleasablePtr<Model>>::iterator erase(typename std::vector<ReleasablePtr<Model>>::iterator pos, const bool load = true); // Remove model at the specified position from the list and calls model's Delete() method. Load models first if they were not loaded yet (lazy loading)
typename std::vector<ReleasablePtr<Model>>::iterator erase(typename std::vector<ReleasablePtr<Model>>::iterator start, typename std::vector<ReleasablePtr<Model>>::iterator end, const bool load = true); // Remove models range from the list and calls models' Delete() method. Load models first if they were not loaded yet (lazy loading)
void clear(const bool load); // Clear models and call theirs Delete() method. If "load" is true, models first loaded (if they are not loaded yet). If "load" is false, models won't be loaded and relation will be marked as already loaded so other operations will not load models (unless clear(true) is called)
// Relation controlling/customization methods
TDbRelation<Model> *Select(const String &column);
TDbRelation<Model> *Select(const String &column, const String &alias);
TDbRelation<Model> *Select(const StringKeyValue &column);
TDbRelation<Model> *Select(const StringArray &columns);
TDbRelation<Model> *Select(const StringKeyValueArray &columns);
TDbRelation<Model> *Distinct(const bool &value);
TDbRelation<Model> *From(const String &table);
TDbRelation<Model> *From(const String &table, const String &alias);
TDbRelation<Model> *From(const StringArray &tables);
TDbRelation<Model> *From(const StringKeyValueArray &tables);
TDbRelation<Model> *InnerJoin(const String &table, DbCondition on);
TDbRelation<Model> *InnerJoin(const String &table, const String &alias, DbCondition on);
TDbRelation<Model> *InnerJoin(const IDbQuery::DbJoin &table);
TDbRelation<Model> *LeftJoin(const String &table, DbCondition on);
TDbRelation<Model> *LeftJoin(const String &table, const String &alias, DbCondition on);
TDbRelation<Model> *LeftJoin(const IDbQuery::DbJoin &table);
TDbRelation<Model> *RightJoin(const String &table, DbCondition on);
TDbRelation<Model> *RightJoin(const String &table, const String &alias, DbCondition on);
TDbRelation<Model> *RightJoin(const IDbQuery::DbJoin &table);
TDbRelation<Model> *Where(DbCondition condition);
TDbRelation<Model> *Where(const DbConditions &conditions);
TDbRelation<Model> *AndWhere(DbCondition condition);
TDbRelation<Model> *OrWhere(DbCondition condition);
TDbRelation<Model> *GroupBy(const String &column);
TDbRelation<Model> *GroupBy(const StringArray &columns);
TDbRelation<Model> *Having(DbCondition condition);
TDbRelation<Model> *Having(const DbConditions &conditions);
TDbRelation<Model> *AndHaving(DbCondition condition);
TDbRelation<Model> *OrHaving(DbCondition condition);
TDbRelation<Model> *OrderBy(const String &column, const DbOrder &order);
TDbRelation<Model> *OrderBy(const DbOrderByArray &columns);
TDbRelation<Model> *Limit(const int64 &limit);
TDbRelation<Model> *Offset(const int64 &offset);
ReleasablePtr<TDbActiveQuery<Model>> Query(); // Return Active Query prefilled with relation loading conditions
};
Namespace: | nitisa |
Include: | Nitisa/Db/DbRelation.h |