Represent a nil association as json null

If an association was nil, which is not unusual, the existing code would raise
an exception like "NoMethodError: undefined method `id' for nil:NilClass".

Collection associations were already ok because they tend to return something
non-nil like [] when they are empty.