On 09.11.2008, at 6:51, Dan Kubb (dkubb) wrote:

>
> Perhaps an argument to the association like :auto_constrain => true|
> false.. where it would default to true (I would want to do the safest
> thing possible as much as possible).

:sql_constraints => true/false may make more sense, imho.
(or :builtin_constraints maybe?..)

> I also think the :protect option should be the default when someone
> doesn't specify the :dependent constraint.  I think it's rare in most
> apps that have data you care about to allow orphan records (where the
> parent is deleted but not the children).  I mean, you wouldn't be
> using dm-constraints if that wasn't the case so it's the safest
> default :)

Good point. It is safe in both senses: data consistency and folks'  
assumptions.

> Also, we're trying to steer clear of "databasey" terms, so perhaps
> this would be better:
>
>  :protect|:destroy|:destroy!|:set_nil|:skip  # or maybe :nillify ? I
> dunno, what do you think?

There should be both :set_nil and :set_nil!
:set_nil instantiates the model and sets nil (running all hooks,  
validations etc.)
:set_nil! runs bulk UPDATE SQL statement.


:set_nil should rollback current transaction in case of validation  
failure.
:protected should rollback current transaction in case of non-empty  
set of dependencies.

Therefore, in case of presence of any dependency to be updated/ 
destroyed, #destroy method MUST start a new transaction (if it was not  
started by the parent already).


The good spec looks like this:

DM::Constraints.default_constraints (attr_accessor, :protect by default)
DM::Constraints.sql_constraints (boolean attr_accessor, true by default)

Note: I really need these globals to set default rules for the whole  
app. In current application I would use the following:
   DM::Constraints.default_constraints = :destroy
   DM::Constraints.sql_constraints = false

Association options:

:sql_constraints => true|false  # default is  
DM::Constraints.sql_constraints
:dependent =>  # default is DM::Constraints.default_constraints
   :protect,  # aborts transaction when set is not empty
   :destroy,  # safe destroy in a loop
   :destroy!, # unsafe bulk delete
   :set_nil,  :nullify,  :nillify,  :nil,  # safe update with  
validations (all of these are aliases :-)
   :set_nil!, :nullify!, :nillify!, :nil!, # unsafe bulk update
   nil, :skip                              # skip foreign key  
constraints (aliases)

+ automatic transactions with raising an error in case of invalid  
record or a protected set.
+ infinite loop detection (cyclic dependencies): when detected,  
transaction is aborted. User should specify appropriate #destroy hooks  
or specific dependency options to avoid such situation.

I think it is going to be awesome!


PS. I don't know much about built-in sql constraints, but it might be  
interesting to make destroy/nullify/skip options affect these also.




--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"DataMapper" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/datamapper?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to