Dashboard > ActiveRecord > ... > Documentation > Hooks
Hooks
Added by Tim Haines, last edited by Daniel Rothmaler on Aug 20, 2007  (view change)
Labels: 
(None)


Hooks

ActiveRecordHooksBase

TH:  I think I read somewhere that Interceptors are now the preferred approach over hooks - can someone confirm or deny via editing.  

Sometimes it's necessary to interfere in the process of saving, loading or deletion. In order to do that, simply override the available hooks:

  • BeforeSave(IDictionary state)
  • BeforeLoad(IDictionary state)
  • BeforeDelete(IDictionary state)

Suppose you want to enforce the current date/time when a post is created:

protected override bool BeforeSave(IDictionary state)
{
    state["Created"] = DateTime.Now;
    return true;
}

Site running on a free Atlassian Confluence Community License granted to Castle Project. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.5.4 Build:#809 Jun 12, 2007) - Bug/feature request - Contact Administrators