lib/netzke/basepack/form_panel/fields.rb in netzke-basepack-0.7.4 vs lib/netzke/basepack/form_panel/fields.rb in netzke-basepack-0.7.5

- old
+ new

@@ -8,16 +8,15 @@ # Items with normalized fields (i.e. containing all the necessary attributes needed by Ext.form.FormPanel to render a field) def items @form_panel_items ||= begin res = normalize_fields(super || data_class && data_class.netzke_attributes || []) # netzke_attributes as default items # if primary key isn't there, insert it as first - if data_class && !res.detect{ |f| f[:name] == data_class.primary_key} + if data_class && !res.detect{ |f| f[:name] == data_class.primary_key.to_s} primary_key_item = normalize_field(data_class.primary_key.to_sym) @fields_from_config[data_class.primary_key.to_sym] = primary_key_item res.insert(0, primary_key_item) end - res end end # Hash of fully configured fields, that are referenced in the items. E.g.: @@ -119,17 +118,14 @@ # Sets the proper xtype of an asociation field def detect_association_with_method(c) if c[:name].index('__') assoc_name, method = c[:name].split('__').map(&:to_sym) - if method && assoc = data_class.reflect_on_association(assoc_name) - assoc_column = assoc.klass.columns_hash[method.to_s] - assoc_method_type = assoc_column.try(:type) - if c[:nested_attribute] - c[:xtype] ||= xtype_for_attr_type(assoc_method_type) - else - c[:xtype] ||= assoc_method_type == :boolean ? xtype_for_attr_type(assoc_method_type) : xtype_for_association - end + assoc_method_type = data_adapter.get_assoc_property_type(assoc_name, method) + if c[:nested_attribute] + c[:xtype] ||= xtype_for_attr_type(assoc_method_type) + else + c[:xtype] ||= assoc_method_type == :boolean ? xtype_for_attr_type(assoc_method_type) : xtype_for_association end end end # RECURSIVELY extracts fields configuration from :items