Fixes for new serialization. Handle more edge cases.

- Better handling of Null, SNull, SEnum and SData.
- Also a fix for foreign key names being incorrect due to
  `Context.getLocalClass()` returning the `Main` class
  when in a `Context.onGenerate` context.
Don't try to call setter if relationship is null...