Closed kolkov closed 7 years ago
Please read this section https://github.com/go-ozzo/ozzo-dbx#crud-operations (search for "composite")
If I have this table structure with composite PK (movie_id, person_id, occupation_id)?
type DbMoviePersonMap struct {
MovieId int `db:"pk"`
PersonId int `db:"pk"`
OccupationId int `db:"pk"`
Importance int
Note string
}
How can I get one row from this table? for example: movie_id: 1, person_id: 1, occupation_id: 1
Only this way?
// SELECT * FROM order_item WHERE order_id=100 AND item_id=20
db.Select().Where(dbx.HashExp{"order_id": 100, "item_id": 20}).One(&orderItem)
Yes, see doc:
// Model selects the row with the specified primary key and populates the model with the row data.
//
// The model variable should be a pointer to a struct. If the query does not specify a "from" clause,
// it will use the model struct to determine which table to select data from. It will also use the model
// to infer the name of the primary key column. Only simple primary key is supported. For composite primary keys,
// please use Where() to specify the filtering condition.
Thanks!
Hi! How to use CRUD when PRIMARY KEY is a multiple-column index, not a single column?