Hi,
I have an object Order with a collection of lines OrderLines.
when i modify this object adding lines to Order.Lines collection and saving with Order.Save, the lines are persisted to the database.
But, when i remove a line with Order.Lines.Remove the line remove correctly from the collection but the Order.Save method don't persist this change (in database the record wasn't deleted).
In Attributes i have the relation marked as Delete:=True
what am i doing wrong???
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The delete:=True will ensure that when the order header is deleted all order lines get deleted.
Technically, removing an object from a collection is not the same as deleting it from the database. The reasoning being that other objects may also be referencing the item you just removed.
To ensure that the line is deleted when the collection is removed you need to manually delete the line.
I've never been sure about what the "correct" way of handling collection changes is, since an auto delete in a recursive collections could conceivably remove data that should not be removed.
- Richard.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Just to explain the recursive thing a little more...
Assume I have a 1-M association from classA to classB and a 1-1 from the ClassB to the ClassA.
If both the associations are marked as delete = true then removing a single item from the ClassB collection would result in the ClassA object and the entire ClassB collection being deleted, even though you may have only wanted the ClassA and a single ClassB object deleted. The other objects may have been referenced elsewhere and should not have been removed.
I'm not sure I've explained it properly so tell me if that doesn't make sense.
- Richard.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I have an object Order with a collection of lines OrderLines.
when i modify this object adding lines to Order.Lines collection and saving with Order.Save, the lines are persisted to the database.
But, when i remove a line with Order.Lines.Remove the line remove correctly from the collection but the Order.Save method don't persist this change (in database the record wasn't deleted).
In Attributes i have the relation marked as Delete:=True
what am i doing wrong???
The delete:=True will ensure that when the order header is deleted all order lines get deleted.
Technically, removing an object from a collection is not the same as deleting it from the database. The reasoning being that other objects may also be referencing the item you just removed.
To ensure that the line is deleted when the collection is removed you need to manually delete the line.
I've never been sure about what the "correct" way of handling collection changes is, since an auto delete in a recursive collections could conceivably remove data that should not be removed.
- Richard.
Just to explain the recursive thing a little more...
Assume I have a 1-M association from classA to classB and a 1-1 from the ClassB to the ClassA.
If both the associations are marked as delete = true then removing a single item from the ClassB collection would result in the ClassA object and the entire ClassB collection being deleted, even though you may have only wanted the ClassA and a single ClassB object deleted. The other objects may have been referenced elsewhere and should not have been removed.
I'm not sure I've explained it properly so tell me if that doesn't make sense.
- Richard.
you explain it perfectly. thank you.