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

On model update nil column values become empty string #119

Open
gabceb opened this issue Dec 14, 2020 · 1 comment
Open

On model update nil column values become empty string #119

gabceb opened this issue Dec 14, 2020 · 1 comment

Comments

@gabceb
Copy link

gabceb commented Dec 14, 2020

First, thanks for the great gem! This has been a lifesaver for me and my team.

I do have a small issue. I am happy to do the work but unsure what is the best way to move forward.

When updating db records via rails_db, text fields with original nil values are changed to '' even when they are not updated. I have been digging into the code and I noticed this is kind of expected because simple_form cannot distinguish between an actual empty string and a nil value but unfortunately this is an issue for any column that has a unique index OR if there is any code that needs to do different things with '' and nil.

I can see 2 potential solutions to this

  • Allow for more complex blacklisting or whitelisting of tables and specific columns. This would make these columns not show on the edit form and never override the values. The clear downside is that the user is forever limited to view or edit these columns
  • Add better casting from ActiveRecord::Base.connection to an actual model and allow usage of things like https://github.com/rubiety/nilify_blanks
  • Override the update action of the controller and clean up some params that are problematic when empty

If someone has experienced the same issue or has any idea it would be great to hear how they fixed this. Until this is solved we cannot use the edit function of the Rails_db 😢

@igorkasyanchuk
Copy link
Owner

Hello @gabceb,
thank you for your issue, and I hope you can try to make a fix.

https://github.com/igorkasyanchuk/rails_db/blob/master/lib/rails_db/table.rb#L51-L56

maybe here if you can add something, before_save callback, or anything like that. But I want to avoid the situation when a field with '' will be set to NULL because of this change.

Or blacklisting some columns as you said. I've already implemented it for tables. But for columns, I think a new configuration could be added.

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

No branches or pull requests

2 participants