QString QDjangoCompiler::databaseColumn(const QString &name) { QDjangoMetaModel model = baseModel; QString modelPath; QString modelRef = referenceModel(QString(), &model); QStringList bits = name.split(QLatin1String("__")); while (bits.size() > 1) { const QByteArray fk = bits.first().toLatin1(); QDjangoMetaModel foreignModel; if (!model.foreignFields().contains(fk)) { // this might be a reverse relation, so look for the model // and if it exists continue foreignModel = QDjango::metaModel(fk); if (!foreignModel.isValid()) break; reverseModelRefs[bits.first()] = foreignModel.primaryKey(); } else { foreignModel = QDjango::metaModel(model.foreignFields()[fk]); } // store reference if (!modelPath.isEmpty()) modelPath += QLatin1String("__"); modelPath += bits.first(); modelRef = referenceModel(modelPath, &foreignModel); model = foreignModel; bits.takeFirst(); } const QDjangoMetaField field = model.localField(bits.join(QLatin1String("__")).toLatin1()); return modelRef + QLatin1Char('.') + driver->escapeIdentifier(field.column(), QSqlDriver::FieldName); }
QString QDjangoCompiler::databaseColumn(const QString &name) { QDjangoMetaModel model = baseModel; QString modelName; QString modelPath; QString modelRef = referenceModel(QString(), &model, false); QStringList bits = name.split(QLatin1String("__")); while (bits.size() > 1) { const QByteArray fk = bits.first().toLatin1(); QDjangoMetaModel foreignModel; bool foreignNullable = false; if (!modelPath.isEmpty()) modelPath += QLatin1String("__"); modelPath += bits.first(); if (!model.foreignFields().contains(fk)) { // this might be a reverse relation, so look for the model // and if it exists continue foreignModel = QDjango::metaModel(fk); QDjangoReverseReference rev; const QMap<QByteArray, QByteArray> foreignFields = foreignModel.foreignFields(); foreach (const QByteArray &foreignKey, foreignFields.keys()) { if (foreignFields[foreignKey] == baseModel.className()) { rev.leftHandKey = foreignModel.localField(foreignKey + "_id").column(); break; } } if (rev.leftHandKey.isEmpty()) { qWarning() << "Invalid field lookup" << name; return QString(); } rev.rightHandKey = foreignModel.primaryKey(); reverseModelRefs[modelPath] = rev; } else {