I fought with this one for a little while. The field is a string field, and postgres doesn't do any implicit conversion (unlike mysql, which does). When a client posts json, they will mostly likely pass an id value in as an integer, which causes this code to error without the to_s