-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Fix joins in db.Find(AndCount)
#28978
Conversation
@@ -133,27 +133,28 @@ type FindOptionsOrder interface { | |||
|
|||
// Find represents a common find function which accept an options interface | |||
func Find[T any](ctx context.Context, opts FindOptions) ([]*T, error) { | |||
sess := GetEngine(ctx) | |||
sess := GetEngine(ctx).Where(opts.ToConds()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JoinFunc
is a func(sess Engine)
which can be called with xorm.Engine
and xorm.Session
. Inside the join func sess.Join
is used. Now the problem is that Session.Join
adds the JOIN
to the statement while Engine.Join
creates a new Session
which gets discarded afterwards. So calling the JoinFunc
with xorm.Engine
does "nothing" while calling with xorm.Session
does what it should.
GetEngine(ctx)
returns a xorm.Engine
and Where(...)
creates the needed Session
.
if orderOpt, ok := opts.(FindOptionsOrder); ok { | ||
if order := orderOpt.ToOrders(); order != "" { | ||
sess.OrderBy(order) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add order support for Find
.
if joinOpt, ok := opts.(FindOptionsJoin); ok { | ||
for _, joinFunc := range joinOpt.ToJoins() { | ||
if err := joinFunc(sess); err != nil { | ||
return nil, 0, err | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add join support for FindAndCount
.
* origin/main: [skip ci] Updated translations via Crowdin Fix UI Spacing Errors in mirror settings (go-gitea#28990) Add htmx guidelines (go-gitea#28993) Some refactor for git http (go-gitea#28995) Fix an actions schedule bug (go-gitea#28942) Fix doc img path in profile readme (go-gitea#28994) Introduce htmx and use it to avoid full page load on `Subscribe` and `Follow` (go-gitea#28908) Fix joins in `db.Find(AndCount)` (go-gitea#28978) Update golang links to use https (go-gitea#28980) Fix google logo in security page (go-gitea#28982)
* giteaofficial/main: Revert "Speed up loading the dashboard on mysql/mariadb (go-gitea#28546)" (go-gitea#29006) Update dorny/paths-filter action (go-gitea#29003) [skip ci] Updated translations via Crowdin Fix UI Spacing Errors in mirror settings (go-gitea#28990) Add htmx guidelines (go-gitea#28993) Some refactor for git http (go-gitea#28995) Fix an actions schedule bug (go-gitea#28942) Fix doc img path in profile readme (go-gitea#28994) Introduce htmx and use it to avoid full page load on `Subscribe` and `Follow` (go-gitea#28908) Fix joins in `db.Find(AndCount)` (go-gitea#28978) Update golang links to use https (go-gitea#28980) Fix google logo in security page (go-gitea#28982) Also match weakly validated ETags (go-gitea#28957)
No description provided.