Have you tried the hook methods yet?  You can specify a symbol and it
will call that method, or you can specify a block and it will execute
it.

Do a search for Hooks on the sequel rdoc readme.

http://sequel.rubyforge.org/rdoc/

Example of some hooks:

after_create do
  some_work
end

OR

after_create :some_work

Example of how you might use it:

class Comment < Sequel::Model
  many_to_one :post
  after_create :increment_post_cache
  after_destroy :decrement_post_cache

  private
  def increment_post_cache
    self.post.increment_comment_cache
  end
  def decrement_post_cache
    self.post.decrement_comment_cache
  end
end

class Post < Sequel::Model
  one_to_many :comments

  def increment_comment_cache
    self.comment_cache += 1
    self.save
  end
  def decrement_comment_cache
    self.comment_cache -= 1
    self.save
  end
end
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sequel-talk" 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/sequel-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to