Recursive toJSON breaks for missing relations

Added a quick test + fix.