If you are trying to create a table to store metadata about the
relationship of two entities, e.g. Product and Store and the quantity of
product available at that store. You may wish to use a composite foreign
key relationship.
If you also wish to use gorm to generate the SQL to create the schema,
but default gorm will add the auto_increment keyword to tables which are
both primary and integer. This is a undesirable for composite foreign
key relationships and generates invalid sql statements.
If you have a struct field which is a primary key and is marked as a
foreign key, disable the auto increment behavior while generating the
schema.
This commit allows you to pass a string or an existing database
connection as the source for gorm. The dialect is still required
because a) there is no common reference to it as far as i know, and
b) gorm allows the dialect to differ from the driver. So, for the sake
of simplicity, you still have to specity the dialect.
This is useful if you have an existing transaction, but still
want to use gorm to format your queries.
This is dependent on the defintion of DB in pkg database/sql having
the field 'dsn', which is the database source, obtained via reflect.
This commit adds more ways of specifying selects:
-) You can now pass in a []string. This is mostly for convenience,
since you may want to dynamically create a list of fields to be
selected.
-) You can now use variables. This is important because a select
could take user input. For example, finding a MAX between a record
and a given number could be easily done using select, and then
you don't have to process anything in backend logic. This is also
necessary to use postgres text search capabilities (which actaully
play nicely with the rest of gorm).
-) You can now chain select calls. This could be useful in
conjunction with gorm's scopes functionality.