Merge d14e48cdd939f886df0cf5f5d53c347faa48bf57 into 9acaa33324bbcc78239a1c913d4f1292c12177b9
This commit is contained in:
		
						commit
						eeb1ca2f95
					
				
							
								
								
									
										50
									
								
								table_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										50
									
								
								table_test.go
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,50 @@
 | 
				
			|||||||
 | 
					package gorm_test
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import "testing"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type Example struct {
 | 
				
			||||||
 | 
						Id uint64 `gorm:"column:id; primary_key:yes"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (e *Example) TableName() string {
 | 
				
			||||||
 | 
						return "exampling"
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//Test to reproduce invalid/non-existant TableName behaviour
 | 
				
			||||||
 | 
					func TestInsertWithTableName(t *testing.T) {
 | 
				
			||||||
 | 
						DB.Exec("drop table examples;")
 | 
				
			||||||
 | 
						DB.Exec("drop table exampling;")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						exampling := Example{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := DB.CreateTable(exampling).Error; err != nil {
 | 
				
			||||||
 | 
							t.Error(err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := DB.Save(exampling).Error; err != nil {
 | 
				
			||||||
 | 
							t.Error(err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := DB.Exec("SELECT count(*) from exampling;").Error; err != nil {
 | 
				
			||||||
 | 
							t.Error(err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestInsertWithTableNameExplicit(t *testing.T) {
 | 
				
			||||||
 | 
						DB.Exec("drop table examples;")
 | 
				
			||||||
 | 
						DB.Exec("drop table exampling;")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						exampling := Example{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := DB.Table("exampling").CreateTable(exampling).Error; err != nil {
 | 
				
			||||||
 | 
							t.Error(err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := DB.Table("exampling").Save(exampling).Error; err != nil {
 | 
				
			||||||
 | 
							t.Error(err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := DB.Exec("SELECT count(*) from exampling;").Error; err != nil {
 | 
				
			||||||
 | 
							t.Error(err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user