Module: RESTFramework::CreateModelMixin

Included in:
ModelControllerMixin
Defined in:
lib/rest_framework/controller_mixins/models.rb

Overview

Mixin for creating records.

Instance Method Summary collapse

Instance Method Details

#createObject



582
583
584
# File 'lib/rest_framework/controller_mixins/models.rb', line 582

def create
  return api_response(self.create!, status: :created)
end

#create!Object

Perform the ‘create!` call and return the created record.



587
588
589
590
591
592
593
594
595
596
597
598
599
# File 'lib/rest_framework/controller_mixins/models.rb', line 587

def create!
  create_from = if self.create_from_recordset && self.get_recordset.respond_to?(:create!)
    # Create with any properties inherited from the recordset. We exclude any `select` clauses in
    # case model callbacks need to call `count` on this collection, which typically raises a SQL
    # `SyntaxError`.
    self.get_recordset.except(:select)
  else
    # Otherwise, perform a "bare" create.
    self.class.get_model
  end

  return create_from.create!(self.get_create_params)
end