Migration adding :null => false to nullable field. #64

Closed
ddgromit opened this Issue Dec 26, 2012 · 5 comments

Projects

None yet

4 participants

@ddgromit

My migration with a nullable money field

class CreateProducts < ActiveRecord::Migration
  def change
    create_table :product do |t|
      t.string :name

      t.money :price
      t.money :price_optional, :null => true
    end
  end
end

creates this schema.rb, ignoring the :null option.

create_table "product", :force => true do |t|
    t.string  "name"
    t.integer "price_cents",             :default => 0,     :null => false
    t.string  "price_currency",          :default => "USD", :null => false
    t.integer "price_optional_cents",    :default => 0,     :null => false
    t.string  "price_optional_currency", :default => "USD", :null => false
end

This is causing the monetize :allow_nil to fail at the SQL level when saving a model with a nil value.

Am I passing through the null option incorrectly?

@alup
Member
alup commented Jan 13, 2013

@ddgromit this is not implemented in the current instance. Would you be interested to implement this?

@semmons99
Member

no activity, closing

@semmons99 semmons99 closed this Nov 28, 2013
@brycesenz

Hello,

I am looking for this feature as well. Your README seems to indicate that null values are supported, but I'm having the same problem as the original user. Has this been fixed yet?

@alup
Member
alup commented Jan 26, 2014

The above example is not correct according to the helper syntax. It should have been written like this:

class CreateProducts < ActiveRecord::Migration
  def change
    create_table :product do |t|
      t.string :name

      t.money :price
      t.money :price_optional, amount: { null: true }
    end
  end
end

You can take a look at the following spec for details:

https://raw.github.com/RubyMoney/money-rails/master/spec/active_record/migration_extensions/table_spec.rb

@brycesenz

Ah, that makes sense. Thanks for the quick response!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment