@@ -49,7 +49,7 @@ type CreateInterface[T any] interface {
4949 Limit (offset int ) ChainInterface [T ]
5050 Offset (offset int ) ChainInterface [T ]
5151 Joins (query clause.JoinTarget , on func (db JoinBuilder , joinTable clause.Table , curTable clause.Table ) error ) ChainInterface [T ]
52- Join (jt clause.JoinTarget , on func ( db ExternalJoinBuilder , joinTable clause.Table , curTable clause.Table ) error ) ChainInterface [T ]
52+ Join (jt clause.JoinTarget , on clause.Expression , moreOn ... clause.Expression ) ChainInterface [T ]
5353 Preload (association string , query func (db PreloadBuilder ) error ) ChainInterface [T ]
5454 Select (query string , args ... interface {}) CreateInterface [T ]
5555 Omit (columns ... string ) CreateInterface [T ]
@@ -82,7 +82,7 @@ type ChainInterface[T any] interface {
8282 Limit (offset int ) ChainInterface [T ]
8383 Offset (offset int ) ChainInterface [T ]
8484 Joins (query clause.JoinTarget , on func (db JoinBuilder , joinTable clause.Table , curTable clause.Table ) error ) ChainInterface [T ]
85- Join (jt clause.JoinTarget , on func ( db ExternalJoinBuilder , joinTable clause.Table , curTable clause.Table ) error ) ChainInterface [T ]
85+ Join (jt clause.JoinTarget , on clause.Expression , andOn ... clause.Expression ) ChainInterface [T ]
8686 Preload (association string , query func (db PreloadBuilder ) error ) ChainInterface [T ]
8787 Select (query string , args ... interface {}) ChainInterface [T ]
8888 Omit (columns ... string ) ChainInterface [T ]
@@ -133,12 +133,6 @@ type JoinBuilder interface {
133133 Or (query interface {}, args ... interface {}) JoinBuilder
134134}
135135
136- type ExternalJoinBuilder interface {
137- Where (query interface {}, args ... interface {}) JoinBuilder
138- Not (query interface {}, args ... interface {}) JoinBuilder
139- Or (query interface {}, args ... interface {}) JoinBuilder
140- }
141-
142136type PreloadBuilder interface {
143137 Scopes (... func (db * Statement )) PreloadBuilder
144138 Unscoped () PreloadBuilder
@@ -473,8 +467,17 @@ func (c chainG[T]) Joins(jt clause.JoinTarget, on func(db JoinBuilder, joinTable
473467 })
474468}
475469
476- func (c chainG [T ]) Join (jt clause.JoinTarget , on func ( db ExternalJoinBuilder , joinTable clause.Table , curTable clause.Table ) error ) ChainInterface [T ] {
470+ func (c chainG [T ]) Join (jt clause.JoinTarget , on clause.Expression , andOn ... clause.Expression ) ChainInterface [T ] {
477471 return c .with (func (db * DB ) * DB {
472+ var expression clause.Expression
473+ if len (andOn ) > 0 {
474+ allOn := []clause.Expression {on }
475+ allOn = append (allOn , andOn ... )
476+ expression = clause.AndConditions {Exprs : allOn }
477+ } else {
478+ expression = on
479+ }
480+
478481 if jt .Table == "" || jt .Table == clause .CurrentTable {
479482 jt .Table = clause .JoinTable (strings .Split (jt .Association , "." )... ).Name
480483 }
@@ -485,11 +488,7 @@ func (c chainG[T]) Join(jt clause.JoinTarget, on func(db ExternalJoinBuilder, jo
485488 }
486489
487490 q := joinBuilder {db : db .Session (& Session {NewDB : true , Initialized : true }).Table (jt .Table )}
488- if on != nil {
489- if err := on (& q , clause.Table {Name : jt .Table }, clause.Table {Name : clause .CurrentTable }); err != nil {
490- db .AddError (err )
491- }
492- }
491+ q .Where (expression )
493492
494493 join := clause.Join {
495494 Type : jt .Type ,
0 commit comments