Fixed a bug when foreign key was not set when saving collections of related models;