gen icon indicating copy to clipboard operation
gen copied to clipboard

Are there reserved words that shouldn't be used in model names?

Open gmenih opened this issue 2 years ago • 1 comments

Your Question

Are there any words we should avoid from using in model names? For example, I created a model named Transaction, and when I generate DAO, I get this error in the SetDefault func in gen.go

invalid operation: cannot take address of Q.Transaction (value of type func(fc func(tx *Query) error, opts ...*sql.TxOptions) error)

There are also errors all over the generated code wherever this Transaction model is used.

The document you expected this should be explained

Either resolve this issue, list reserved words in GORM documentation, and provide a workaround. IMO, Transaction is a valid model name, so maybe rename the Query.Transaction method to Query.Tx?

gmenih avatar Sep 29 '23 11:09 gmenih