gorm/many2many_test.go

13 lines
568 B
Go
Raw Normal View History

2014-07-29 06:59:13 +04:00
package gorm_test
import "testing"
func TestQueryManyToManyWithRelated(t *testing.T) {
db.Model(&User{}).Related(&[]Language{}, "Languages")
// SELECT `languages`.* FROM `languages` INNER JOIN `user_languages` ON `languages`.`id` = `user_languages`.`language_id` WHERE `user_languages`.`user_id` = 111
// db.Model(&User{}).Many2Many("Languages").Find(&[]Language{})
// db.Model(&User{}).Many2Many("Languages").Add(&Language{})
// db.Model(&User{}).Many2Many("Languages").Remove(&Language{})
// db.Model(&User{}).Many2Many("Languages").Replace(&[]Language{})
}