[odb-users] composite ID containing an auto-incrementable field

Boris Kolpackov boris at codesynthesis.com
Fri Jul 24 07:17:21 EDT 2020


Sten Kultakangas <ratkaisut at gmail.com> writes:

> Boris, I am going to make the necessary modifications to
> odb/relational/source.cxx and odb/relational/mssql/source.cxx but i wonder
> if you have some work-in-progress branch having the relevant modifications
> that I can easily backport to the stable 2.5.0 branch ?

No, I haven't looked into this.


> If you haven't yet worked on this issue, then do you have instructions for
> contributors on how to make a patch that can be incorporated into the
> official version control branch ?

You can either email the patch directly or create a pull request on your
favorite Git hosting platform (GitHub, etc).

Note that for this to be merged to master we would need the fix for all
the databases as well as a test.


> P.S. Actually tenant_id does not belong to the primary key, but i see no
> other way to force odb to generate UPDATE statement having condition WHERE
> tenant_id=X and id=X which is necessary for data integrity as our API does
> not currently perform sanity-checks on the user-supplied ID but instead it
> determines the tenant the API user belongs to.

One somewhat admittedly hackish way to achieve this could be to "overlay"
two classes over the same database table. One class would have the simple
auto id to be used for persist and the other would have the composite id
without auto to be used for update. You might also need to tweak the
generated database schema depending on the database system used.



More information about the odb-users mailing list