#include "AirportModel.h"
#include "MessageException.h"

AirportModel::AirportModel(QObject *parent)
: QxModelBase<Airport>(parent)
{
    setAutoUpdate();
//    setShowEmptyLine(true);
}

AirportModel::~AirportModel()
{
}


void AirportModel::fetchByName(const QString &name, int pageIndex)
{
    //关系t解决orcle标识符过长问题
	qx::QxSqlQuery query;
	if (!name.isEmpty())
        query.where("t." + Airport::column_NAME()).containsString(name);
    query.orderAsc("t." + Airport::column_ID());

	QStringList relations;
	relations << "<t>";

	this->countWithRelation(query, relations);
	this->limit(query, pageIndex);
	QSqlError error = this->qxFetchByQuery(query, relations);
	if (error.isValid())
		throw MessageException(error.text());
}
