// Insert a user
func (s *UserStorage) Insert(c model.User) (string, error) {
	c.Chocolates = make([]model.Chocolate, len(c.ChocolatesIDs))
	err := s.updateChocolatesByChocolatesIDs(&c)
	if err != nil {
		return "", err
	}
	s.db.Create(&c)
	if s.db.Error != nil {
		return "", s.db.Error
	}
	return c.GetID(), nil
}
func (s UserStorage) getOneWithAssociations(id int64) (model.User, error) {
	var user model.User
	s.db.First(&user, id)
	s.db.Model(&user).Related(&user.Chocolates, "Chocolates")
	if err := s.db.Error; err == gorm.ErrRecordNotFound {
		errMessage := fmt.Sprintf("User for id %s not found", id)
		return model.User{}, api2go.NewHTTPError(errors.New(errMessage), errMessage, http.StatusNotFound)
	} else if err != nil {
		return model.User{}, err
	}
	user.ChocolatesIDs = make([]string, len(user.Chocolates))
	for i, choc := range user.Chocolates {
		user.ChocolatesIDs[i] = choc.GetID()
	}
	return user, nil
}
func (s *UserStorage) updateChocolatesByChocolatesIDs(u *model.User) error {
	u.Chocolates = make([]model.Chocolate, len(u.ChocolatesIDs))
	for i, chocID := range u.ChocolatesIDs {
		intID, err := strconv.ParseInt(chocID, 10, 64)
		if err != nil {
			return err
		}
		// TODO: Fix N+1 query problem
		s.db.First(&u.Chocolates[i], intID)
	}
	return nil
}