RAILS: edit turns null strings into empty strings

W

Wybo Dekker

In my mysql database I stored empty strings as NULL's, so that I can test
fields to be nil.

(It's shorter, nicer and more logical to test "if field" rather than
"if field == ''")

But when I edit a record, all NULL's in char fields are replaced with an
empty string ('').

Is there a way to prevent this?
Or is my idea wrong in the first place?
 
C

Charles Steinman

Wybo said:
In my mysql database I stored empty strings as NULL's, so that I can test
fields to be nil.

(It's shorter, nicer and more logical to test "if field" rather than
"if field == ''")

But when I edit a record, all NULL's in char fields are replaced with an
empty string ('').

Is there a way to prevent this?
Or is my idea wrong in the first place?

I think the most simple and semantic way of going about it would be to
store empty fields as empty strings and use "if field.empty?" to
determine whether there's anything there. You should be able to convert
empty fields to nil in your update method, though, if you want to go
about it that way.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top