Re: Problems understanding delete behavior

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Fri Dec 12 2003 - 02:00:32 EST

  • Next message: Mark Evenson: "Re: Problems understanding delete behavior"

    Hi Mark,

    On Dec 10, 2003, at 3:53 AM, Mark Evenson wrote:

    > My lack of expereience with Object Relational mappings is showing
    > here, but
    > my next question is why this would not be the default behavior for a
    > system
    > such as Cayenne?

    Default setting for delete rules is always "no action" in the Modeler.
    Modeler does not try to guess other defaults. This may not be the
    smartest behavior, but at least it is consistent. :-)

    > Naievely trying to set all my delete rules to "Nullify" when I set a
    > toMany
    > relationship's delete rule to "Nullify", I get two identical warning
    > messages from the modeler about "ObjRelationship XXX has a Nullify
    > delete
    > rule and a mandatory reverse relationship" on saving the project.
    > This is
    > confusing as all of my relationship have teh "Update Reverse" box
    > checked,
    > but as to how they are "mandatory reverse relationship" is unknown.

    "Mandatory" refers to the fact that a relationship target is a table
    column (DbAttribute) that does not allow nulls.

    This validation message addresses a specific case when you have a
    "to-many" from PK to FK, and FK column is defined as NOT NULL. Setting
    the rule to "Nullify" means that deleting a source of this relationship
    would result in a NULL FK of the destination, hence the warning.

    So in the most common case you should set "to-one" rules as "Nullify"
    and "to-many" as "Cascade" (or "Deny" if this is what you need).
    Generally this should follow the business logic of your app and the
    common sense ("When I delete an object X, what do I want to happen to a
    related object Y?")

    Hope this helps. Though it is pretty late at night and I my writing is
    becoming incomprehensible.

    Andrus



    This archive was generated by hypermail 2.0.0 : Fri Dec 12 2003 - 02:00:38 EST