Class: Engine2::StarToManyListMeta

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

Overview

  • to Many

Direct Known Subclasses

StarToManyFieldMeta, StarToManyLinkListMeta

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

def post_run

super
unless @request_meta_proc
    request{|h| decode_panel_title h}
end

end



176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# File 'lib/engine2/meta/list_meta.rb', line 176

def list_context query, handler
    handler.permit parent = handler.params[:parent_id]
    model = assets[:model]
    assoc = assets[:assoc]
    case assoc[:type]
    when :one_to_many
        keys = assoc[:keys]
        condition = parent.empty? ? false : Hash[keys.map{|k| k.qualify(model.table_name)}.zip(split_keys(parent))]
        if handler.params[:negate]
            query = query.exclude(condition)
            query = query.or(Hash[keys.zip([nil])]) if keys.all?{|k|model.db_schema[k][:allow_null] == true} # type_info[:required] ?
            query
        else
            query.where(condition)
        end
    when :many_to_many
        q_pk = model.primary_keys_qualified
        j_table = assoc[:join_table]
        l_keys = assoc[:left_keys].map{|k| k.qualify(j_table)}
        r_keys = assoc[:right_keys].map{|k| k.qualify(j_table)}
        r_keys_vals = Hash[r_keys.zip(q_pk)]
        l_keys_vals = parent.empty? ? false : Hash[l_keys.zip(split_keys(parent))]

        if handler.params[:negate]
            query.exclude(model.db[j_table].select(nil).where(r_keys_vals, l_keys_vals).exists)
        else
            # query.qualify.join(j_table, [r_keys_vals, l_keys_vals])
            query.qualify.left_join(j_table, r_keys_vals).filter(l_keys_vals)
        end
    else unsupported_association
    end
end

#pre_runObject



156
157
158
159
# File 'lib/engine2/meta/list_meta.rb', line 156

def pre_run
    super
    panel_title "#{glyphicon('list')} #{LOCS[assets[:assoc][:name]]}"
end