Class: Engine2::StarToManyFieldAction

Inherits:
StarToManyListAction show all
Defined in:
lib/engine2/action/list.rb

Overview

*_to_many_field

Direct Known Subclasses

StarToManyFieldLinkListAction

Instance Attribute Summary

Attributes included from ActionListSupport

#filters, #orders

Attributes inherited from Action

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

Instance Method Summary collapse

Methods inherited from StarToManyListAction

#post_run

Methods inherited from ListAction

#invoke, #list_search, #post_run

Methods included from ActionListSupport

#field_tabs, #filter, #filter_case_insensitive, #order, #post_process, #post_run, #search_live, #search_template, #searchable, #searchable_tabs, #select_toggle_menu, #sortable, #template

Methods included from ActionModelSupport

#hide_pk, #node_defined, #show_pk, #unsupported_association

Methods included from ActionAPISupport

#config, #decorate, #field_filter, #fields, #fields!, #hide_fields, #loc!, #render, #show_fields

Methods included from ActionTabSupport

#field_tabs, #select_tabs, #tab

Methods included from ActionPanelSupport

#modal_action, #panel, #panel_class, #panel_footer, #panel_header, #panel_panel_template, #panel_template, #panel_title, #post_run

Methods included from ActionMenuSupport

#menu, #menu?, #post_process

Methods included from ActionOnChangeSupport

#on_change

Methods included from ActionDraggableSupport

#draggable, #post_run

Methods included from ActionQuerySupport

#find_record, #get_query, #post_run, #query, #select

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

#list_context(query, handler) ⇒ Object



242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
# File 'lib/engine2/action/list.rb', line 242

def list_context query, handler
    changes = handler.param_to_json(:changes)
    model = assets[:model]
    unlinked = changes[:unlink].to_a + changes[:delete].to_a + changes[:modify].to_a.map{|m|join_keys(model.primary_keys.map{|k|m[k]})}
    linked = changes[:link]
    query = super(query, handler)

    pks = model.primary_keys_qualified

    if handler.params[:negate]
        query = unlinked.reduce(query){|q, unl|q.or pks.zip(split_keys(unl))}
        query = linked.reduce(query){|q, ln|q.where(pks.zip(split_keys(ln)).sql_negate)}
    else
        query = unlinked.reduce(query){|q, unl|q.where(pks.zip(split_keys(unl)).sql_negate)}
        query = case assets[:assoc][:type]
        when :one_to_many
            linked.reduce(query){|q, ln|q.or pks.zip(split_keys(ln))}
        when :many_to_many
            linked.reduce(query){|q, ln|q.or pks.zip(split_keys(ln))}.distinct
        else unsupported_association
        end unless linked.empty?
    end

    added = changes[:create].to_a + changes[:modify].to_a
    cols = get_query.columns
    query = added.reduce query do |q, a|
        q.union(model.db.select(*cols.map{|c|a[c]}), all: true, alias: model.table_name)
    end

    query
end

#pre_runObject



236
237
238
239
240
# File 'lib/engine2/action/list.rb', line 236

def pre_run
    super
    modal_action false
    panel_panel_template false
end