Move primary key nil check for has_many to correct place