Class: Engine2::StarToManyFieldMeta

Inherits:
StarToManyListMeta show all
Defined in:
lib/engine2/meta/list_meta.rb

Overview

*_to_many_field

Direct Known Subclasses

StarToManyFieldLinkListMeta

Instance Attribute Summary

Attributes included from MetaListSupport

#filters, #orders

Attributes inherited from Meta

#action, #assets, #invokable, #static

Instance Method Summary collapse

Methods inherited from ListMeta

#invoke, #list_search, #post_run

Methods included from MetaListSupport

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

Methods included from MetaModelSupport

#action_defined, #get_type_info, #hide_pk, #show_pk, #unsupported_association

Methods included from MetaAPISupport

#config, #decorate, #field_filter, #hide_fields, #info, #info!, #render, #show_fields

Methods included from MetaTabSupport

#field_tabs, #lazy_tab, #select_tabs

Methods included from MetaPanelSupport

#glyphicon, #modal_action, #panel, #panel_class, #panel_panel_template, #panel_template, #panel_title, #post_run

Methods included from MetaMenuSupport

#menu, #post_process

Methods included from MetaOnChangeSupport

#on_change

Methods included from MetaQuerySupport

#get_query, #post_run, #query, #select

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, #request, #request_meta_proc_params, #response, #split_keys

Constructor Details

This class inherits a constructor from Engine2::Meta

Instance Method Details

#list_context(query, handler) ⇒ Object



232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
# File 'lib/engine2/meta/list_meta.rb', line 232

def list_context query, handler
    unlinked = handler.param_to_json(:unlinked)
    linked = handler.param_to_json(:linked)
    query = super(query, handler)
    model = assets[:model]
    pks = model.primary_keys_qualified

    if handler.params[:negate]
        query = unlinked.map{|ln| pks.zip(split_keys(ln))}.inject(query){|q, c| q.or c}
        # query = query.or *unlinked.map{|unl| Hash[model.primary_keys.zip(split_keys(unl))]}.inject{|q, c| q | c}
        query = query.where *linked.map{|ln| pks.zip(split_keys(ln)).sql_negate}

    else
        query = query.where *unlinked.map{|unl| pks.zip(split_keys(unl)).sql_negate}
        # query = query.or *linked.map{|ln| model.primary_keys.zip(split_keys(ln))}
        # query = query.or *linked.map{|ln| Hash[model.primary_keys.zip(split_keys(ln))]}.inject{|q, c| q | c}
        case assets[:assoc][:type]
        when :one_to_many
            query = linked.map{|ln| pks.zip(split_keys(ln))}.inject(query){|q, c| q.or c}
        when :many_to_many
            query = linked.map{|ln| pks.zip(split_keys(ln))}.inject(query){|q, c| q.or c}.distinct
        else unsupported_association
        end unless linked.empty?
    end

    query
end

#pre_runObject



225
226
227
228
229
230
# File 'lib/engine2/meta/list_meta.rb', line 225

def pre_run
    super
    modal_action false
    panel_panel_template false
    # panel_template nil
end