Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nullify on a not-null column should set to default value #106

Open
jrmhaig opened this issue Jul 18, 2021 · 1 comment
Open

nullify on a not-null column should set to default value #106

jrmhaig opened this issue Jul 18, 2021 · 1 comment
Labels

Comments

@jrmhaig
Copy link
Collaborator

jrmhaig commented Jul 18, 2021

If a field is set as follows:

amoeba do
  enable
  nullify :test_field
end

and test_field is set as not null in the database then the value of a duplicate should be the default value, not null. However, at present, the field is set to nil and the resulting instance cannot be saved.

To reproduce

Create a migration:

class CreateTestModels < ActiveRecord::Migration[6.1]
  def change
    create_table :test_models do |t|
      t.string :test_string, null: false, default: 'Test default'

      t.timestamps
    end
  end
end

and the corresponding model:

class TestModel < ApplicationRecord
  amoeba do
    enable
    nullify :test_string
  end
end

Then:

irb> test = TestModel.create
irb> test.test_string
=> "Test default"
irb> dup = test.amoeba_dup
irb> dup.save

Expected behaviour: dup is saved successfully with test_string set to "Test default".
Actual behaviour: Not-null violation exception raised.

@jrmhaig jrmhaig added the bug label Jul 18, 2021
@jrmhaig jrmhaig mentioned this issue Jul 20, 2021
10 tasks
@nateleavitt
Copy link

Also experiencing this bug. I have a jsonb column with a default value of an empty Hash. Upon duplicating, the field is nil instead of {}.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants