sbfaulkner / sequel_cascading

my take on cascading deletes via a plugin for sequel

This URL has Read+Write access

name age message
file .gitignore Sat Jan 10 08:54:19 -0800 2009 first commit [sbfaulkner]
file MIT-LICENSE Sat Jan 10 08:54:19 -0800 2009 first commit [sbfaulkner]
file README.markdown Sun May 10 09:28:27 -0700 2009 define callback methods instead of using deprec... [sbfaulkner]
file Rakefile Sun Jan 11 20:07:48 -0800 2009 add tests [sbfaulkner]
directory lib/ Sun May 10 09:26:31 -0700 2009 Use a before_destroy method instead of the old ... [foca]
file sequel_cascading.gemspec Sun May 10 09:28:56 -0700 2009 define callback methods instead of using deprec... [sbfaulkner]
directory test/ Mon Jan 12 10:17:43 -0800 2009 add support for :nullify and :restrict [sbfaulkner]
README.markdown

sequel_cascading

my take on cascading deletes via a plugin for sequel

WHY?

DRY up my code.

No more explicit before_destroy to delete the children of one_to_many associations.

Installation

Run the following if you haven't already:

$ gem sources -a http://gems.github.com

Install the gem(s):

$ sudo gem install -r sbfaulkner-sequel_cascading

Example

require 'rubygems'
require 'sequel'

class Comment < Sequel::Model
  many_to_one :post
end

class Post < Sequel::Model
  one_to_many :comment, :order => :name

  # destroy any associated records too
  is :cascading, :destroy => :comments

  # or, if you want to null the foreign key instead, you could...
  # is :cascading, :nullify => :comments

  # or, if you want the destroy to fail, you would...
  # is :cascading, :restrict => :comments
end

UPDATES

1.0.4

  • [foca] define callback methods instead of using deprecated api

1.0.3

  • added support for :nullify and :restrict options

TODO

  • add :null and :deny support?
  • publish in sequel www/pages/plugins

Legal

Author: S. Brent Faulkner brentf@unwwwired.net
License: Copyright © 2009 unwwwired.net, released under the MIT license