One problem with using dm-constraints is that it doesn't support sqlite3 - so testing can become a little annoying. The other problem, as far as I can tell, is that it relies of the underlying database to propagate changes. This means if you're doing anything wacky where a foreign-key constraint isn't actually defined in the database, it won't do what you'd expect. dm-constraints isn't a drop in replacement for :dependent => :destroy.
Given the limitations of constraints, and the fact that isn't synonymous with :dependent => :destroy, I'm a little surprised a plugin hasn't cropped up. I'm no db expert, but I'm guessing that perhaps using the built in database operations are more efficient than using callback hooks - which would be my guess as to why it isn't out there? On May 19, 11:26 am, Martin Gamsjaeger <[email protected]> wrote: > Miles, > > You will need dm-constraints to do this. > > http://github.com/datamapper/dm-more/tree/next/dm-constraints > > With this in place, you can do something like > > has n, :users, :constraint => :destroy > > You can find all supported constraints in the docs for dm-constraints > > I should mention though, that the above link is for the next branch > aka 0.10.0. If you're using dm-constraints-0.9.11, then there is a bug > (probably in extlib) which forces you to add the :constraint option > explicitly to *all* your "has" associations (whereas :constraint => > :protect should be the default if you leave it out) > > Which finally brings me to the point I wanted to bring up on this ML > for quite some time now. > > Is this bug fixed in the next branch? > > The problem with this is the following. Say I'm writing a plugin which > adds "has" associations to a model, then (with this behavior/bug) I'm > *forced* to add the :constraint option to every call to "has". This > isn't really a problem *if* dm would simply ignore this option in case > dm-constraints isn't available. However, from what I see in my current > app (which actually really confuses me), dm auto_migrates the foreign > keys, even though dm-constraints doesn't seem to get loaded !?! Here's > what I get when running merb -iv > > mungo:trippings snusnu$ merb -iv > ~ Running bootloaders... > Loading init file from /Users/snusnu/projects/github/trippings/config/init.rb > Loading > /Users/snusnu/projects/github/trippings/config/environments/development.rb > ~ Loaded DEVELOPMENT Environment... > ~ Expanding RUBY_PATH... > ~ loading gem 'merb-core' ... > ~ loading gem 'merb-assets' ... > ~ loading gem 'merb-cache' ... > ~ loading gem 'merb-helpers' ... > ~ loading gem 'merb-slices' ... > ~ loading gem 'merb-auth-core' ... > ~ loading gem 'merb-auth-more' ... > ~ Registered slice 'MerbAuthSlicePassword' located at > /opt/local/lib/ruby/gems/1.8/gems/merb-auth-slice-password-1.0.11 > ~ loading gem 'merb-auth-slice-password' ... > ~ loading gem 'merb_datamapper' ... > ~ loading gem 'merb-param-protection' ... > ~ loading gem 'merb-mailer' ... > ~ loading gem 'merb-parts' ... > ~ loading gem 'merb-flash' ... > ~ loading gem 'data_objects' ... > ~ loading gem 'do_sqlite3' ... > ~ loading gem 'dm-core' ... > ~ loading gem 'do_mysql' ... > ~ loading gem 'dm-types' ... > ~ loading gem 'dm-validations' ... > ~ loading gem 'dm-aggregates' ... > ~ loading gem 'dm-migrations' ... > ~ loading gem 'dm-timestamps' ... > ~ loading gem 'dm-is-remixable' ... > ~ loading gem 'dm-is-list' ... > ~ loading gem 'dm-is-state_machine' ... > ~ loading gem 'dm-is-taggable' ... > ~ loading gem 'dm-is-awesome_set' ... > ~ loading gem 'dm-paperclip' ... > ~ loading gem 'dm-sweatshop' ... > ~ loading gem 'dm-is-rateable' ... > ~ loading gem 'dm-is-commentable' ... > ~ loading gem 'dm-is-localizable' ... > ~ loading gem 'dm-accepts_nested_attributes' ... > ~ loading gem 'merb_resource_controller' ... > ~ loading gem 'texp' ... > ~ loading gem 'tzinfo' ... > > I can't see any dm-constraints in there, however, dm happily adds > > ALTER TABLE ... ADD CONSTRAINT .. FOREIGN_KEY ... REFERENCES ... ON > DELETE .. ON UPDATE > > when I run DataMapper.auto_migrate! > > what's happening there :)? > > cheers > snusnu > > On Tue, May 19, 2009 at 18:13, MilesTogoe <[email protected]> wrote: > > > does datamapper support the command: > > has n, :users, :dependent=> destroy > > > I'm getting error ondependent --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
