mirror of https://github.com/go-gorm/gorm.git
Don't merge clause From
This commit is contained in:
parent
1f05cb7e55
commit
72a64bef11
|
@ -33,9 +33,5 @@ func (from From) Build(builder Builder) {
|
|||
|
||||
// MergeClause merge from clause
|
||||
func (from From) MergeClause(clause *Clause) {
|
||||
if v, ok := clause.Expression.(From); ok {
|
||||
from.Tables = append(v.Tables, from.Tables...)
|
||||
from.Joins = append(v.Joins, from.Joins...)
|
||||
}
|
||||
clause.Expression = from
|
||||
}
|
||||
|
|
|
@ -38,6 +38,16 @@ func TestFrom(t *testing.T) {
|
|||
[]clause.Interface{
|
||||
clause.Select{}, clause.From{
|
||||
Tables: []clause.Table{{Name: "users"}},
|
||||
Joins: []clause.Join{
|
||||
{
|
||||
Type: clause.RightJoin,
|
||||
Table: clause.Table{Name: "profiles"},
|
||||
ON: clause.Where{
|
||||
[]clause.Expression{clause.Eq{clause.Column{Table: "profiles", Name: "email"}, clause.Column{Table: clause.CurrentTable, Name: "email"}}},
|
||||
},
|
||||
},
|
||||
},
|
||||
}, clause.From{
|
||||
Joins: []clause.Join{
|
||||
{
|
||||
Type: clause.InnerJoin,
|
||||
|
@ -51,19 +61,9 @@ func TestFrom(t *testing.T) {
|
|||
Using: []string{"company_name"},
|
||||
},
|
||||
},
|
||||
}, clause.From{
|
||||
Joins: []clause.Join{
|
||||
{
|
||||
Type: clause.RightJoin,
|
||||
Table: clause.Table{Name: "profiles"},
|
||||
ON: clause.Where{
|
||||
[]clause.Expression{clause.Eq{clause.Column{Table: "profiles", Name: "email"}, clause.Column{Table: clause.CurrentTable, Name: "email"}}},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"SELECT * FROM `users` INNER JOIN `articles` ON `articles`.`id` = `users`.`id` LEFT JOIN `companies` USING (`company_name`) RIGHT JOIN `profiles` ON `profiles`.`email` = `users`.`email`", nil,
|
||||
"SELECT * FROM `users` INNER JOIN `articles` ON `articles`.`id` = `users`.`id` LEFT JOIN `companies` USING (`company_name`)", nil,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue