diff --git a/clause/from.go b/clause/from.go index 59b0bfaf..1ea2d595 100644 --- a/clause/from.go +++ b/clause/from.go @@ -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 } diff --git a/clause/from_test.go b/clause/from_test.go index 3ebb754c..75422f8e 100644 --- a/clause/from_test.go +++ b/clause/from_test.go @@ -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, }, }