Class: Engine2::SaveMeta
- Includes:
- MetaApproveSupport
- Defined in:
- lib/engine2/meta/save_meta.rb
Direct Known Subclasses
Instance Attribute Summary
Attributes included from MetaApproveSupport
Attributes inherited from Meta
#action, #assets, #invokable, #static
Instance Method Summary collapse
Methods included from MetaApproveSupport
#after_approve, #allocate_record, #before_approve, included, #invoke, #post_run, #record, #validate, #validate_fields, #validate_record
Methods included from MetaModelSupport
#action_defined, #get_type_info, #hide_pk, #pre_run, #show_pk, #unsupported_association
Methods inherited from Meta
#action_defined, #check_static_meta, #dynamic?, #freeze_meta, #get, http_method, #http_method, inherited, #initialize, #invoke!, #lookup, #merge, #meta_type, meta_type, #post_process, #post_run, #pre_run, #request, #request_meta_proc_params, #split_keys
Constructor Details
This class inherits a constructor from Engine2::Meta
Instance Method Details
#validate_and_approve(handler, record, json) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/engine2/meta/save_meta.rb', line 8 def validate_and_approve handler, record, json record.skip_save_refresh = true record.raise_on_save_failure = false model = assets[:model] assoc = assets[:assoc] mtm_insert = record.new? && assoc && assoc[:type] == :many_to_many save = lambda do|c| if super(handler, record, json) result = record.save(transaction: false, validate: false) if result && mtm_insert handler.permit parent_id = json[:parent_id] model.db[assoc[:join_table]].insert(assoc[:left_keys] + assoc[:right_keys], split_keys(parent_id) + record.primary_key_values) end result end end (model.validation_in_transaction || mtm_insert) ? model.db.transaction(&save) : save.(nil) end |