Rename relations to associations

This commit is contained in:
Jinzhu 2014-07-30 14:30:21 +08:00
parent 371e6af99e
commit ba95de5c50
4 changed files with 29 additions and 26 deletions

25
association.go Normal file
View File

@ -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
}

View File

@ -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")
}

View File

@ -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}
}

View File

@ -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
}