-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
[Question] Does ORM support some shortcut operations #2831
Comments
文档里面不是都有吗 |
Isn't it all in the document? |
我好像没找到,妳能发我链接看看吗? @wln732 |
I can't seem to find it, can you send me the link? @wln732 w |
|
|
这只是 插入数据的保存 ,并没有实现我说的那几个方法 @wln732 |
This is just the preservation of inserted data, and does not implement the methods I mentioned @wln732 |
1.firstOrNew() || FirstOrInit() 找不到则根据给定的数据创建一个 Entity 实例,但未保存数据库 |
1.firstOrNew() || If FirstOrInit() cannot be found, an Entity instance is created according to the given data, but the database is not saved |
|
|
// FirstOrInit这个api完全是多此一举,
db.FirstOrInit(&user, User{Name: "non_existing"})
// user -> User{Name: "non_existing"}
// 为什么不能是这种写法呢
var user = User{Name:"jack"}
db.First(&user) 你上面那种写法,没有找到数据,是不是还要在反射给&user赋值? var user *User
// 如果没有找到数据,user还是nil什么都不做
db.One(&user) |
// The FirstOrInit api is completely superfluous,
db. FirstOrInit(&user, User{Name: "non_existing"})
// user -> User{Name: "non_existing"}
// Why can't it be written this way?
var user = User{Name:"jack"}
db. First(&user) If you did not find the data in the way you wrote above, do you still need to assign a value to &user in reflection? var user *User
// If no data is found, user or nil do nothing
db. One(&user)
|
@shuqingzai @wln732 大家好,在 |
@shuqingzai @wln732 Hello everyone, there are really not many quick packaging methods in |
Hello @shuqingzai. We like your proposal/feedback and would appreciate a contribution via a Pull Request by you or another community member. We thank you in advance for your contribution and are looking forward to reviewing it! |
如下一些很实用且高频使用的快捷方法,无论是
laravel
或gorm
都支持这些方法,但在 gf 的 ORM 文档我似乎没有找到,可能是我疏忽了,请问支持吗?first() 、take() 、last()
根据条件获取第一条(根据主键排序 ASC)、获取一条、获取最新一条(根据主键排序 DESC) 记录firstOrNew() || FirstOrInit()
找不到则根据给定的数据创建一个 Entity 实例,但未保存数据库firstOrCreate()
找不到则根据给定的数据创建一个 Entity 实例且自动保存数据库updateOrCreate()
根据给定的条件查找数据,如果存在则更新给定的数据,否则使用给定的数据创建记录1. What version of
Go
and system type/arch are you using?#-> % go version go version go1.20.6 darwin/amd64
2. What version of
GoFrame
are you using?3. Can this issue be re-produced with the latest release?
4. What did you do?
5. What did you expect to see?
6. What did you see instead?
The text was updated successfully, but these errors were encountered: