goadesign / gorma

Storage generation plugin for Goa
http://goa.design
MIT License
140 stars 35 forks source link

PK Field declaration required for OneFoo and Get methods to generate with ID arg #123

Closed trevrosen closed 2 years ago

trevrosen commented 8 years ago

When creating a new model, Gorma will automatically create an ID field on your model struct and set a gorm:"primary_key" struct tag. This is great.

What is confusing however is that the generated methods for retrieving a single item from the database won't take an ID parameter without an additional Field declaration in your model for a primary key:

Field("id", gorma.Integer, func() {
  PrimaryKey()
}

Without the above, the Gorm Where method in both the generated OneFoo model helper and the Get model method only have an empty string as an argument, rendering them effectively useless.