Can't update the column of base class?

Forum for posting problems using QxOrm library

Can't update the column of base class?

Postby behtgod » Thu Jul 07, 2016 8:46 am

The base class:
Code: Select all
class SpBaseORM
{

   QX_REGISTER_FRIEND_CLASS(SpBaseORM)
   friend struct qx::dao::detail::QxDao_Trigger<SpBaseORM>;

protected:

   QString m_uuid;
   QDateTime m_createdDate;

public:

   SpBaseORM();
   SpBaseORM(const QString & id);
   virtual ~SpBaseORM();

   QString GetUuid() const;
   QDateTime GetCreatedDate() const;

   void SetUuid(const QString & val);
   void SetCreatedDate(const QDateTime & val);

   static QString ColumnUuid() { return "uuid"; }
   static QString ColumnCreatedDate() { return "created_date"; }

};

typedef QSharedPointer<SpBaseORM> SpBaseORMPtr;
typedef qx::QxCollection<QString, SpBaseORMPtr> SpBaseORMList;
typedef QSharedPointer<SpBaseORMList> SpBaseORMListPtr;

QX_REGISTER_ABSTRACT_CLASS(SpBaseORM)
QX_REGISTER_PRIMARY_KEY(SpBaseORM, QString)
QX_REGISTER_HPP_DATABASEMODELS(SpBaseORM, qx::trait::no_base_class_defined, 0)



Code: Select all
QX_REGISTER_CPP_DATABASEMODELS(SpBaseORM)

namespace qx {

template <>
void register_class(QxClass<SpBaseORM> & t)
{
   qx::IxDataMember * pData = NULL; Q_UNUSED(pData);
   qx::IxSqlRelation * pRelation = NULL; Q_UNUSED(pRelation);
   qx::IxFunction * pFct = NULL; Q_UNUSED(pFct);
   qx::IxValidator * pValidator = NULL; Q_UNUSED(pValidator);

   t.setSoftDelete(qx::QxSoftDelete("deleted"));

   pData = t.id(& SpBaseORM::m_uuid, "uuid", 0);

   pData = t.data(& SpBaseORM::m_createdDate, "createdDate", 0, true, true);
   pData->setName("created_date");

   qx::QxValidatorX<SpBaseORM> * pAllValidator = t.getAllValidator(); Q_UNUSED(pAllValidator);
}

} // namespace qx

SpBaseORM::SpBaseORM() { ; }

SpBaseORM::SpBaseORM(const QString & id) : m_uuid(id) { ; }

SpBaseORM::~SpBaseORM() { ; }

QString SpBaseORM::GetUuid() const { return m_uuid; }

QDateTime SpBaseORM::GetCreatedDate() const { return m_createdDate; }

void SpBaseORM::SetUuid(const QString & val) { m_uuid = val; }

void SpBaseORM::SetCreatedDate(const QDateTime & val) { m_createdDate = val; }



and the derived class:
Code: Select all
class DATABASEMODELSSHARED_EXPORT SpPatientORM : public SpBaseORM
{

   QX_REGISTER_FRIEND_CLASS(SpPatientORM)

protected:

   QString m_name;

public:

   SpPatientORM();
   SpPatientORM(const QString & id);
   virtual ~SpPatientORM();

   QString GetName() const;


   void SetName(const QString & val);


public:

   static QString ColumnName() { return "name"; }
   static QString ColumnUuid() { return "uuid"; }
   static QString ColumnCreatedDate() { return "created_date"; }

public:

   static QString TableName() { return "t_patient"; }
};

typedef QSharedPointer<SpPatientORM> SpPatientORMPtr;
typedef qx::QxCollection<QString, SpPatientORMPtr> SpPatientORMList;
typedef QSharedPointer<SpPatientORMList> SpPatientORMListPtr;

QX_REGISTER_PRIMARY_KEY(SpPatientORM, QString)
QX_REGISTER_HPP_DATABASEMODELS(SpPatientORM, SpBaseORM, 0)


Code: Select all
QX_REGISTER_CPP_DATABASEMODELS(SpPatientORM)

namespace qx {

template <>
void register_class(QxClass<SpPatientORM> & t)
{
   qx::IxDataMember * pData = NULL; Q_UNUSED(pData);
   qx::IxSqlRelation * pRelation = NULL; Q_UNUSED(pRelation);
   qx::IxFunction * pFct = NULL; Q_UNUSED(pFct);
   qx::IxValidator * pValidator = NULL; Q_UNUSED(pValidator);

   t.setName("t_patient");
   t.setSoftDelete(qx::QxSoftDelete("deleted"));

   pData = t.data(& SpPatientORM::m_name, "name", 0, true, true);
   pData->setIsIndex(true);

   qx::QxValidatorX<SpPatientORM> * pAllValidator = t.getAllValidator(); Q_UNUSED(pAllValidator);
}

} // namespace qx

SpPatientORM::SpPatientORM() : SpBaseORM() { ; }

SpPatientORM::SpPatientORM(const QString & id) : SpBaseORM(id) { ; }

SpPatientORM::~SpPatientORM() { ; }

QString SpPatientORM::GetName() const { return m_name; }

void SpPatientORM::SetName(const QString & val) { m_name = val; }





when update with list of colume's name
Code: Select all
SpPatientORM patient;
    patient2.setuuid("b");
    patient2.setname("c");

    QStringList columns;
    columns.append("name");
    columns.append("created_date");
    QSqlError daoError=qx::dao::update(patient,0,columns);

show the message:
ASSERT failure in [QxOrm] qx::QxSqlQueryBuilder<T>::verifyColumns(): "column 'created_date' not found in table 't_patient'"


But I'm sure that exist colume 'created_date' in the 't_patient'.
Any advice to fixed it ?
behtgod
 
Posts: 18
Joined: Mon Nov 16, 2015 8:21 am

Re: Can't update the column of base class?

Postby qxorm » Thu Jul 07, 2016 9:33 am

Hello,

In your base class qx::register_class() function, you wrote :
Code: Select all
   pData = t.data(& SpBaseORM::m_createdDate, "createdDate", 0, true, true);
   pData->setName("created_date");

So you defined a data member with a key equals to 'createdDate', and a column name equals to 'created_date'.
FYI, if you don't write pData->setName("created_date"); , then by default QxOrm library considers : data member key = data member column name.

When you have to refer to this data member, you have to use the data member key, and not the column name.
So just write :
Code: Select all
    QStringList columns;
    columns.append("name");
    columns.append("createdDate");
    QSqlError daoError=qx::dao::update(patient,0,columns);
qxorm
Site Admin
 
Posts: 481
Joined: Mon Apr 12, 2010 7:45 am

Re: Can't update the column of base class?

Postby behtgod » Sun Jul 31, 2016 3:22 pm

Thank you very much!

qxorm wrote:Hello,

In your base class qx::register_class() function, you wrote :
Code: Select all
   pData = t.data(& SpBaseORM::m_createdDate, "createdDate", 0, true, true);
   pData->setName("created_date");

So you defined a data member with a key equals to 'createdDate', and a column name equals to 'created_date'.
FYI, if you don't write pData->setName("created_date"); , then by default QxOrm library considers : data member key = data member column name.

When you have to refer to this data member, you have to use the data member key, and not the column name.
So just write :
Code: Select all
    QStringList columns;
    columns.append("name");
    columns.append("createdDate");
    QSqlError daoError=qx::dao::update(patient,0,columns);
behtgod
 
Posts: 18
Joined: Mon Nov 16, 2015 8:21 am


Return to QxOrm - Help

Who is online

Users browsing this forum: No registered users and 14 guests