Menu

AutoDeleting Lines

homer111
2005-01-29
2013-03-07
  • homer111

    homer111 - 2005-01-29

    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???

     
    • Richard Banks

      Richard Banks - 2005-01-30

      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.

       
      • Richard Banks

        Richard Banks - 2005-01-30

        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.

         
    • homer111

      homer111 - 2005-01-30

      you explain it perfectly. thank you.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.