Class: Engine2::StarToManyListMeta
- Defined in:
- lib/engine2/meta/list_meta.rb
Overview
-
to Many
Direct Known Subclasses
Instance Attribute Summary
Attributes included from MetaListSupport
Attributes inherited from Meta
#action, #assets, #invokable, #static
Instance Method Summary collapse
-
#list_context(query, handler) ⇒ Object
def post_run super unless @request_meta_proc request{|h| decode_panel_title h} end end.
- #pre_run ⇒ Object
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, #select_toggle_menu, #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!, #loc!, #reload_routes!, #render, #show_fields
Methods included from MetaTabSupport
#field_tabs, #lazy_tab, #select_tabs
Methods included from MetaPanelSupport
#footer, #modal_action, #panel, #panel_class, #panel_panel_template, #panel_template, #panel_title, #post_run
Methods included from MetaMenuSupport
Methods included from MetaOnChangeSupport
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 208 |
# 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] parent_keys = split_keys(parent) case assoc[:type] when :one_to_many keys = assoc[:keys] condition = parent_keys.all?(&:empty?) ? false : Hash[keys.map{|k| k.qualify(model.table_name)}.zip(parent_keys)] 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_keys.all?(&:empty?) ? false : Hash[l_keys.zip(parent_keys)] 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_run ⇒ Object
156 157 158 159 |
# File 'lib/engine2/meta/list_meta.rb', line 156 def pre_run super panel_title "#{:list.icon} #{LOCS[assets[:assoc][:name]]}" end |