XORM not holding onto modified TableName for struct after initial sync #1488

Closed
opened 2019-12-02 04:50:22 +00:00 by gnosthi · 5 comments

Please see https://play.golang.org/p/FB_X2Gm0R2k for example.

During the operation of the above code, the table is created as expected. However, once the data is marshalled into the table it fails to keep the correct table name.

Expected:
dbEngine.Sync creates the tablename as defined in TableName() method for the struct and marshals the data into the tablename as defined in TableName method for the struct.

Actual:
dbEngine.Sync creates the tablename as defined in TableName() method for the struct, but tries to marshal the data into tablename defined by the struct name alone. It then fails as the table is not created.

Any help you could provide would be fantastic.

Thanks

Please see https://play.golang.org/p/FB_X2Gm0R2k for example. During the operation of the above code, the table is created as expected. However, once the data is marshalled into the table it fails to keep the correct table name. Expected: dbEngine.Sync creates the tablename as defined in TableName() method for the struct and marshals the data into the tablename as defined in TableName method for the struct. Actual: dbEngine.Sync creates the tablename as defined in TableName() method for the struct, but tries to marshal the data into tablename defined by the struct name alone. It then fails as the table is not created. Any help you could provide would be fantastic. Thanks
Author

Same with "xorm.io/xorm" import

https://play.golang.org/p/Ow7vMJ0S7_p

Same with "xorm.io/xorm" import https://play.golang.org/p/Ow7vMJ0S7_p
Owner

Hi, please use Sync2, Sync has been deprecated.

Hi, please use `Sync2`, `Sync` has been deprecated.
Author

Thank you for the quick response.

Same issue is still occurring though

➜ go run .
StartHere 1Here 2Here 3Here 4panic: mssql: Invalid object name 'sample_total_blocked_by_ip'.

goroutine 1 [running]:
main.main()
/Users/80087228/go/src/local_testing/structs/test/main.go:60 +0x7b1
exit status 2

Thank you for the quick response. Same issue is still occurring though ➜ go run . StartHere 1Here 2Here 3Here 4panic: mssql: Invalid object name 'sample_total_blocked_by_ip'. goroutine 1 [running]: main.main() /Users/80087228/go/src/local_testing/structs/test/main.go:60 +0x7b1 exit status 2
Owner

And could you try

func (s SampleTotalBlockedByIp) TableName() string {
	return "999_sample_total_blocked_by_ip"
}
And could you try ``` func (s SampleTotalBlockedByIp) TableName() string { return "999_sample_total_blocked_by_ip" } ```
Author

Awesome! Thanks for the help. That fixed it right up!

Awesome! Thanks for the help. That fixed it right up!
lunny closed this issue 2021-06-12 09:03:23 +00:00
Sign in to join this conversation.
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: xorm/xorm#1488
No description provided.