Welcome to Working With Rails

 

Discussion Forums

Discuss all things Ruby on Rails with perhaps the web's most vibrant group of Ruby on Rails enthusiasts.
Database NULL values
5 Posts
Database NULL values

I have an application running on SQLServer 2005,

recently I ran into a problem.

object.blank? catches 'nil' and empty values but it fails to recognize 'NULL' values returned from activerecord results.

Is there a way in ruby to detect database NULL values?

Person
Forum Rating: 100
Sign In To Rate Post

rails changes nil to null before saving and also for retrieving from database it changes null to nil. I think you might be storing null as a string and this causing an issue for you.

Thanks Raza,

While googling this issue, I found the "Article":http://thisoldcoder.com/

This fix seems to solve my problem.

Would like to hear comments on this fix?

Person
Forum Rating: 100
Sign In To Rate Post

What about a real string value "NULL" inputted by end user?

I don't think that is a good solution. IMP, it should be the adapter's matter. That means we should catch it by recognizing the column attributes (type?) and then replace the value.

Jerry, there is no MSSQL adapter for Rails. If you feel strongly enough about this, then you should consider writing one.

5 Posts
Login to add your message