Module: Ooor::FieldMethods::ClassMethods
- Defined in:
- lib/ooor/field_methods.rb
Instance Method Summary collapse
- #all_fields ⇒ Object
-
#define_nested_attributes_method(meth) ⇒ Object
this is used by fields_for in ActionView FormHelper.
- #fast_fields(options = {}) ⇒ Object
- #reload_fields_definition(force = false, context = connection.web_session) ⇒ Object
Instance Method Details
#all_fields ⇒ Object
22 23 24 |
# File 'lib/ooor/field_methods.rb', line 22 def all_fields fields.merge(polymorphic_m2o_associations).merge(many2many_associations).merge(one2many_associations).merge(many2one_associations) end |
#define_nested_attributes_method(meth) ⇒ Object
this is used by fields_for in ActionView FormHelper
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/ooor/field_methods.rb', line 34 def define_nested_attributes_method(meth) unless self.respond_to?(meth) self.instance_eval do define_method "#{meth}_attributes=" do |*args| send("#{meth}_will_change!") @associations[meth] = args[0] @loaded_associations[meth] = args[0] end define_method "#{meth}_attributes" do |*args| @loaded_associations[meth] end end end end |
#fast_fields(options = {}) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/ooor/field_methods.rb', line 26 def fast_fields(={}) fields = all_fields fields.keys.select do |k| fields[k]["type"] != "binary" && ([:include_functions] || !fields[k]["function"]) end end |
#reload_fields_definition(force = false, context = connection.web_session) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/ooor/field_methods.rb', line 9 def reload_fields_definition(force=false, context=connection.web_session) if force || !fields @t.fields = {} @columns_hash = {} fields_get = rpc_execute("fields_get", false, context) fields_get.each { |k, field| reload_field_definition(k, field) } @t.associations_keys = many2one_associations.keys + one2many_associations.keys + many2many_associations.keys + polymorphic_m2o_associations.keys logger.debug "#{fields.size} fields loaded in model #{self.name}" Ooor.model_registry.set_template(connection.config, @t) end generate_accessors if fields != {} && (force || !@accessor_defined) #TODOmove in define_accessors method end |