diff --git a/association.go b/association.go new file mode 100644 index 00000000..7e0bc31c --- /dev/null +++ b/association.go @@ -0,0 +1,25 @@ +package gorm + +type Association struct { + Scope *Scope + Column string +} + +func (*Association) Find(value interface{}) { +} + +func (*Association) Append(values interface{}) { +} + +func (*Association) Delete(value interface{}) { +} + +func (*Association) Clear(value interface{}) { +} + +func (*Association) Replace(values interface{}) { +} + +func (*Association) Count(values interface{}) int { + return 0 +} diff --git a/relations_test.go b/association_test.go similarity index 98% rename from relations_test.go rename to association_test.go index 6e89c23e..650fb6a9 100644 --- a/relations_test.go +++ b/association_test.go @@ -138,7 +138,7 @@ func TestQueryManyToManyWithRelated(t *testing.T) { // } newLanguages = []Language{} - db.Model(&user).Many2Many("Languages").Find(&newLanguages) + db.Model(&user).Association("Languages").Find(&newLanguages) if len(newLanguages) != 3 { t.Errorf("Query many to many relations") } diff --git a/main.go b/main.go index 1ef9c13c..4aef5885 100644 --- a/main.go +++ b/main.go @@ -351,6 +351,7 @@ func (s *DB) RemoveIndex(indexName string) *DB { return s } -func (s *DB) Many2Many(column string) *DB { - return s +func (s *DB) Association(column string) *Association { + scope := s.clone().NewScope(s.Value) + return &Association{Scope: scope, Column: column} } diff --git a/many2many.go b/many2many.go deleted file mode 100644 index a10121fd..00000000 --- a/many2many.go +++ /dev/null @@ -1,23 +0,0 @@ -package gorm - -type many2many struct { -} - -func (*many2many) Find(value interface{}) { -} - -func (*many2many) Append(values interface{}) { -} - -func (*many2many) Delete(value interface{}) { -} - -func (*many2many) Clear(value interface{}) { -} - -func (*many2many) Replace(values interface{}) { -} - -func (*many2many) Count(values interface{}) int { - return 0 -}