Callbacks
There is support for callbacks on certain events.
Here is an example:
require "granite_orm/adapter/pg"
class Post < Granite::ORM
adapter pg
before_save :upcase_title
field title : String
field content : String
timestamps
def upcase_title
if title = @title
@title = title.upcase
end
end
endYou can register callbacks for the following events:
Create
before_savebefore_createsaveafter_createafter_save
Update
before_savebefore_updatesaveafter_updateafter_save
Destroy
before_destroydestroyafter_destroy
Last updated