Hello Andrus and list,
Thank you for your helpful replies. My many-to-many relationship
is now working. For better or worse here are the salient parts of
how I've set it up.
Assuming the following many-to-many relationship:
A - AB - B
In the Cayenne Modeler
the DbEntity relationships to AB, defined in A and B have
'To Dep PK' checked.
the ObjEntity to-many relations from A to B and B to A have
Delete Rule = Cascade
I was relieved to learn that 'the cascade stops' at the join table:
ie. removing a 'B' from an 'A' removes the join table entry but not
the 'B' itself. Whew. I suppose that's not so surprising but I
was worried, especially since I strongly agreed with advice from
this list's archives to remove the auto-generated AB ObjEntity (but
of course not the AB DbEntity) and so couldn't control the delete
rule of that missing AB ObjEntity.
Not much was require in the DB schema itself. AB has a compound
primary key consisting of primary keys from A and B. I also
defined the keys of AB to be foriegn keys which causes the
relationships to be auto generated in Cayenne Modeler and which
helped me find some referential integrity problems --
Before deleting an A or B I manually remove its to-many
relationships (and the 'reverse relationships'). This removes
the join table entires. There might be a setting or two somewhere
that would make this happen automatically but I'll leave that to
future explorers since I need to get on with other user stories.
Also, with respect to ref integrity, before adding a B in
many-to-many to an A, I check to see that B isn't already there.
This avoids a duplicate primary key exception when Cayenne tries to
add a duplicate AB join table entry.
Again, thanks for your insights Andrus, I would have been stuck
without the cogent pointers you provided.
Best,
Steve
---Steve Steinitz ph +61 (0)2 9487 7215 Director
Data Tactics Sydney, Australia
www.datatactics.com.au
Web Commerce Development Project Estimation and Planning Software Development MacOS X Support
This archive was generated by hypermail 2.0.0 : Sun Feb 08 2004 - 06:29:40 EST