Model will add simple CRUD semantics to your operation to find/create a model in
Note that this is not limited to ActiveRecord.
class Create < Trailblazer::Operation include Model model Comment, :create
::model method you have to define what model class to work with. The second argument specifies the action.
This will override
model! as follows.
class Create < Trailblazer::Operation def model! Comment.new end
The model is automatically created for you in
#setup! and hence available in
validate, you don’t need to provide the model anymore.
def process(params) model #=> <Comment body=""> # created via #model!. validate(params[:thing]) do .. end end
The following actions for
::model are available.
process, you now have a new or existing
You may override
update_model! from the
Model module if you need to change behavior.
Note that this is really simple behavior. Do not use this module when you plan to use more complex models.