Fix for #375 - toJSON should include IDs of unregistered models

Possible fix for #375

Side effect (seems fine to me) is that it also continues to return IDs of deleted models, which
seems less magic and more expected to me - also allows for 'soft deletes' where an object itself
is deleted but other objects can still have references to it.