Class: Engine2::StarToManyUnlinkMetaBase

Inherits:
Meta show all
Includes:
MetaModelSupport
Defined in:
lib/engine2/meta/link_meta.rb

Instance Attribute Summary

Attributes inherited from Meta

#action, #assets, #invokable, #static

Class Method Summary collapse

Instance Method Summary collapse

Methods included from MetaModelSupport

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

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

Constructor Details

This class inherits a constructor from Engine2::Meta

Class Method Details



80
81
82
83
84
85
86
# File 'lib/engine2/meta/link_meta.rb', line 80

def self.many_to_many_unlink_db model, assoc, parent, ids
    p_pk = Hash[assoc[:left_keys].zip(parent)]
    ds = model.db[assoc[:join_table]]
    ids.each do |id|
        ds.where(p_pk, Hash[assoc[:right_keys].zip(Sequel::split_keys(id))]).delete
    end
end


63
64
65
66
67
68
# File 'lib/engine2/meta/link_meta.rb', line 63

def self.one_to_many_unlink_db model, assoc, ids
    keys = assoc[:keys]
    ids.each do |id|
        model.where(model.primary_keys_hash(Sequel::split_keys(id))).update(Hash[keys.zip([nil])])
    end
end

Instance Method Details



70
71
72
73
74
75
76
77
78
# File 'lib/engine2/meta/link_meta.rb', line 70

def many_to_many_unlink_db parent, ids
    model = assets[:model]
    assoc = assets[:assoc]

    model.db.transaction do
        self.class.many_to_many_unlink_db model, assoc, Sequel::split_keys(parent), ids
    end
    {}
end


49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/engine2/meta/link_meta.rb', line 49

def one_to_many_unlink_db handler, ids
    model = assets[:model]
    assoc = assets[:assoc]
    keys = assoc[:keys]
    if keys.all?{|k|model.db_schema[k][:allow_null] == true}
        model.db.transaction do
            self.class.one_to_many_unlink_db model, assoc, ids
        end
        {}
    else
        handler.halt_method_not_allowed LOCS[:"non_nullable"]
    end
end