Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BeforeSave 调用遇到问题 #31

Open
shiweifu opened this issue May 28, 2021 · 2 comments
Open

BeforeSave 调用遇到问题 #31

shiweifu opened this issue May 28, 2021 · 2 comments

Comments

@shiweifu
Copy link

先贴代码:

func beforeSaveItem(req *leancloud.ClassHookRequest) (interface{}, error) {
	// 获取 Item
 	item := new(Item)
  	if err := req.Object.Clone(item); err != nil {
  	  return nil, err
  	}

        // item 和 item.FromUser 都有正确的值	
	fmt.Println("-----beforeSaveItem: ", item)
	fmt.Printf("-----fromUser: %v\n\n", item.FromUser)

         // 一些针对其他字段的操作....

  	return item, nil
}

我配置了 FromUser 字段是必填的,在没有这个 hook 函数时,一切正常。在有这个 hook 函数的时候,保存失败,返回错误信息:

fromUser is required.

是不是这块对于 Pointer 的处理可能有 bug,hook 函数返回的时候,不能正确读取 pointer 类型的字段?

@shiweifu
Copy link
Author

有人处理吗?

应该是没人吧 - -

@KevinGong2013
Copy link

这个应该是你定义类型时fromUser 类型不对。

要用 leanCloud.User 不能用 *leancloud.User

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants