cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tony Giaccone <tgiacc...@gmail.com>
Subject Clearing out many objects that are contained in a to many relationship
Date Tue, 14 Aug 2018 20:11:37 GMT
I have an object that contains a to many relationship to potentially 100's
of thousands of objects.  I read in a file and generate this relationship
based on the contents of that file.

Imagine that after the relationship has been created, we realize that the
file contained errors and we want to recreate this relationship by reading
a new file that describes the complete set of entries in the relationship.

Note, I don't want to delete the objects that make up the toMany
relationship. I just want to break the relationship between the source and
the many destination objects.

My first thought is to null out the relationship, There's a foreign key in
the dependent object that describes its parent.  So first step is set all
those values to null.

Then I'll iterate through the list, recreating the relationship based on
the contents of the file.

This is the brute force approach that solves the problem of what do I do
about entries in the old list that aren't in the new list.

My question is this. Is there an easy way to break that connection. I
looked didn't see anything.

Essentially want to do this:

Assume two tables t1,t2.
There is a to-Many relationship between t1 and t2.  The foreign key column
in table t2 is fkt1.

update t2   set fkt1 = null where fkt1 = %A_VALUE;

This is kind of counter to the Cayenne way of doing things, but it's a
large number of objects and I can't see the point in iterating through them
on by one to delete the relationship.




Tony

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message