lib/hobo_fields/model.rb in hobo_fields-2.1.1 vs lib/hobo_fields/model.rb in hobo_fields-2.1.2

- old
+ new

@@ -80,17 +80,25 @@ end end # Extend belongs_to so that it creates a FieldSpec for the foreign key - def self.belongs_to_with_field_declarations(name, options={}, &block) + def self.belongs_to_with_field_declarations(name, *args, &block) + if args.size == 0 || (args.size == 1 && args[0].kind_of?(Proc)) + options = {} + args.push(options) + elsif args.size == 1 + options = args[0] + else + options = args[1] + end column_options = {} column_options[:null] = options.delete(:null) if options.has_key?(:null) column_options[:comment] = options.delete(:comment) if options.has_key?(:comment) index_options = {} index_options[:name] = options.delete(:index) if options.has_key?(:index) - bt = belongs_to_without_field_declarations(name, options, &block) + bt = belongs_to_without_field_declarations(name, *args, &block) refl = reflections[name.to_sym] fkey = refl.foreign_key declare_field(fkey.to_sym, :integer, column_options) if refl.options[:polymorphic] declare_polymorphic_type_field(name, column_options)