20#include "KDbConnection.h"
22#include "KDbIndexSchema.h"
23#include "KDbRelationship.h"
24#include "KDbTableSchema.h"
31 : tableSchema(nullptr)
34 , isAutoGenerated(false)
46 for (KDbRelationship* rel : qAsConst(masterOwnedRelationships)) {
47 if (rel->detailsIndex()) {
48 rel->detailsIndex()->detachRelationship(rel);
51 qDeleteAll(masterOwnedRelationships);
55 KDbTableSchema *tableSchema;
60 QSet<KDbRelationship*> masterOwnedRelationships;
63 QList<const KDbRelationship*> masterRelationships;
66 QList<const KDbRelationship*> detailsRelationships;
92 KDbField *parentTableField = parentTable->field(f->name());
93 if (!parentTableField) {
94 kdbWarning() <<
"Could not find field" << f->name() <<
"in parentTable. Empty index will be created!";
95 KDbFieldList::clear();
116 kdbWarning() <<
"Table is already assigned to this index";
120 d->tableSchema =
table;
126 if (!d->tableSchema ||
field->table() != d->tableSchema) {
128 <<
"WARNING: field does not belong to the same table"
138 return d->tableSchema;
143 return d->tableSchema;
148 return d->masterRelationships;
153 return d->detailsRelationships;
158 return d->isAutoGenerated;
163 d->isAutoGenerated = set;
187 d->isPrimary =
false;
192 return d->isForeignKey;
197 d->isForeignKey = set;
198 if (d->isForeignKey) {
227 if (rel->masterIndex() ==
this) {
229 if (!d->masterOwnedRelationships.contains(rel)) {
230 d->masterOwnedRelationships.insert(rel);
233 if (!d->masterRelationships.contains(rel)) {
234 d->masterRelationships.append(rel);
237 }
else if (rel->detailsIndex() ==
this) {
238 if (!d->detailsRelationships.contains(rel)) {
239 d->detailsRelationships.append(rel);
248 d->masterOwnedRelationships.remove(rel);
249 d->masterRelationships.takeAt(d->masterRelationships.indexOf(rel));
250 d->detailsRelationships.takeAt(d->detailsRelationships.indexOf(rel));
bool addField(KDbField *field)
virtual KDbField * field(int id)
KDbField::List * fields()
KDbFieldList(bool owner=false)
Provides information about database index that can be created for a database table.
virtual bool addField(KDbField *field)
void setAutoGenerated(bool set)
void setPrimaryKey(bool set)
QList< const KDbRelationship * > detailsRelationships() const
bool isPrimaryKey() const
bool isAutoGenerated() const
void attachRelationship(KDbRelationship *rel)
~KDbIndexSchema() override
QList< const KDbRelationship * > masterRelationships() const
void setForeignKey(bool set)
void detachRelationship(KDbRelationship *rel)
bool isForeignKey() const
void setTable(KDbTableSchema *table)
Assigns this index to table table() must be nullptr and table must be not be nullptr.
KDbObject(int type)
Creates new object of type type. */.
A database connectivity and creation framework.