Class: Engine2::StarToManyUnlinkActionBase

Inherits:
Action show all
Includes:
ActionModelSupport
Defined in:
lib/engine2/action/link.rb

Instance Attribute Summary

Attributes inherited from Action

#assets, #invokable, #meta, #node, #static

Instance Method Summary collapse

Methods included from ActionModelSupport

#hide_pk, #node_defined, #show_pk, #unsupported_association

Methods inherited from Action

action_type, #action_type, #arguments, #check_anonymous_action_class, #check_static_action, #define_invoke, #define_method, #dynamic?, #execute, #freeze_action, #http_method, http_method, inherit, inherited, #initialize, #invoke!, #join_keys, #lookup, #merge, #node_defined, #post_process, #post_run, #repeat, #request, #request_action_proc_params, #split_keys

Constructor Details

This class inherits a constructor from Engine2::Action

Instance Method Details



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/engine2/action/link.rb', line 56

def invoke_unlink_db handler, parent, ids
    model = assets[:model]
    assoc = assets[:assoc]

    case assoc[:type]
    when :one_to_many
        keys = assoc[:keys]
        if keys.all?{|k|model.db_schema[k][:allow_null] == true}
            model.db.transaction do
                ids.each do |id|
                    model.where(model.primary_keys_hash(split_keys(id))).update(Hash[keys.zip([nil])])
                end
            end
        else
            handler.halt_method_not_allowed LOCS[:"non_nullable"]
        end
    when :many_to_many
        model.db.transaction do
            p_pk = Hash[assoc[:left_keys].zip(parent)]
            ds = model.db[assoc[:join_table]]
            ids.each do |id|
                ds.where(p_pk & Hash[assoc[:right_keys].zip(split_keys(id))]).delete
            end
        end
    else unsupported_association
    end
    {}
end

#pre_runObject



51
52
53
54
# File 'lib/engine2/action/link.rb', line 51

def pre_run
    super
    execute "[action.parent().invoke(), action.panel_close()]"
end