[odb-users] Update the id of an object which has a relation with the other object

علی دانش adanesh at noornet.net
Tue Apr 19 05:37:31 EDT 2016


Hi Boris,

I want to update the id of an object which has a relation with the other object. For example:
QList<std::shared_ptr<OTHER_CLASS>> m_otherClassList;
I used the method that you mentioned before. The idea was to map another special
class to the same table that would allow you to change the id.

Here is an outline:

#pragma db object table("my_object")
class my_object // You original object.
{
  ...

  #pragma db id column("id")
  unsigned int id;
};

#pragma db object table("my_object")
struct my_object_id
{
  my_object_id (unsigned int o, unsigned int n): old_id (o), new_id (n) {}

  #pragma db id column("id")
  unsigned int old_id;

  #pragma db column("id")
  unsigned int new_id;
};

my_object o = ...;

db.update (my_object_id (o.id, -o.id));


But in my case, because of the relation, I got the "foreign key
constraint failed" error. I used odb 2.4.0 and sqlite.
Can you please advice how to resolve this problem?

Ali



More information about the odb-users mailing list