class Engine2::StarToManyLinkAction
Public Instance Methods
invoke(handler)
click to toggle source
# File lib/engine2/action/link.rb, line 15 def invoke handler json = handler.post_to_json parent = json[:parent_id] ids = json[:ids] handler.permit parent && ids invoke_link_db handler, split_keys(parent), ids end
invoke_link_db(handler, parent, ids)
click to toggle source
# File lib/engine2/action/link.rb, line 23 def invoke_link_db handler, parent, ids model = assets[:model] assoc = assets[:assoc] case assoc[:type] when :one_to_many model.db.transaction do pk = Hash[assoc[:keys].zip(parent)] ids.each do |id| model.where(model.primary_keys_hash(split_keys(id))).update(pk) end end when :many_to_many p_pk = Hash[assoc[:left_keys].zip(parent)] values = ids.map do |id| p_pk.merge Hash[assoc[:right_keys].zip(split_keys(id))] end model.db[assoc[:join_table]].multi_insert values else unsupported_association end {} end
pre_run()
click to toggle source
Calls superclass method
Engine2::ActionModelSupport#pre_run
# File lib/engine2/action/link.rb, line 10 def pre_run super execute "action.errors || [action.parent().invoke(), action.panel_close()]" end