Print Page | Close Window

Delete Persistence Order

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce Classic
Forum Discription: For .NET 2.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=1382
Printed Date: 23-Apr-2025 at 6:04pm


Topic: Delete Persistence Order
Posted By: dobbo
Subject: Delete Persistence Order
Date Posted: 21-Jul-2009 at 7:32am
Hi all,
 
I have a database with three tables:
 
Account
AccountAddress
Address
 
These are used to describe a many to many relationship between Account and Address.
I also have a field in Account that points to a specific AccountAddress record to define the Primary Address when dealing with that account.
The relationships set up are as follows:
 
Account -> AccountAddress on the appropriate keys
Account -> AccountAddress pointing to a specific record on the appropriate key
AccountAddress -> Address on the appropriate keys.
 
Using Classic DevForce (3.6.2) and a CAB solution based on Cabana, I have a problem when I change the field in Account to point to a different AccountAddress record and delete the original AccountAddress.
 
When I save the Account record I then get an error show below:
 
 
I think this is because the persistence order or, perhaps an issue with our relationships, is wrong.
 
The error is pointing to the relationship pointing to the specific record.
 
If I save the content before deleting, then delete the original address it works but this is not an ideal solution.
 
Does anyone have any suggestions on how I can go about solving this problem.
 
Thanks
 
John



Replies:
Posted By: GregD
Date Posted: 22-Jul-2009 at 1:14pm
John:

I assume that the 1-to-M between Account and AccountAddress is implemented with a foreign key in AccountAddress that points to the parent Account. If Account also has a foreign key that points to AccountAddress (for the primary Address), then we can't know whether to delete AccountAddress entities first, or Account entities, because it depends upon what your user has done with the data in a particular session.

Personally, I would put a boolean field in the AccountAddress table to indicate whether a given AccountAddress record is a primary one, and then enforce a constraint that only one AccountAddress record in a set with the same parent Account be so designated.  Your Account.PrimaryAccountAddress property would then be a custom one that returns the one AccountAddress entity (if there is one) that is (a) a child of your Account instance and (b) is marked as a primary.




Print Page | Close Window