[odb-users] deleting entries on relation table

Boris Kolpackov boris at codesynthesis.com
Thu Jan 30 22:37:21 EST 2014


Hi Simón Emmanuel,

Simón Emmanuel Gutiérrez Brida <simon.gutierrez.brida at gmail.com> writes:

> This won't work in the case were the same pattern is owned by two users,
> that's because when you try to persist the second case the pattern is
> already persisted so an exception is thrown.
> 
> The problem I present can't be solved with just two tables Users and
> Patterns

Ok, so you have a many-to-many relationship and not a one-to-many.

To make persist work in this case you need to first see (e.g.,
with a query) if a pattern with these properties already exists.
If that's the case, then you just use the existing pattern
instead of creating and persisting a new one.

For completeness let me also address your original question:
deleting related User objects when you delete a Pattern from
the database in case of a many-to-many relationship. The two
options are: Either use the on_delete pragma to make the
database do this automatically for you (coming in 2.4.0 but
is already available in a pre-release). Or use query support
for containers, once it is implemented (no ETA for this feature
at the moment).

Boris



More information about the odb-users mailing list