Adds a ForeignKeyed interface similar to the Index interface for defining foreign keys in models. (It only supports single column foreign keys)
Example Schemas
type User struct {
Id hood.Id
Name string
}
type Post struct {
Id hood.Id
Content string
UserId int64
}
func (table *Post) ForeignKeys(foreignKeys *hood.ForeignKeys) {
foreignKeys.Add("test_fk", "user_id", "user", "id", hood.Cascade, hood.Cascade)
}
I added a ReferentialAction type. Cascase, Restrict, NoAction, and SetNull are constants defined. It follows the same pattern that Join does.
name: Name of foreign key constraint
column: The column in the table/model to create the foreign key on
referenceTable: The name of the table with the column the foreign key will reference
referenceColumn: The column in the referenceTable the foreign key will reference
Two functions were added to dialect.go: ForeignKey and ReferentialAction.
Foreign keys are created when the table is created.
Adds a ForeignKeyed interface similar to the Index interface for defining foreign keys in models. (It only supports single column foreign keys)
Example Schemas
I added a ReferentialAction type. Cascase, Restrict, NoAction, and SetNull are constants defined. It follows the same pattern that Join does.
The function signature for foreignKeys.Add is
name: Name of foreign key constraint column: The column in the table/model to create the foreign key on referenceTable: The name of the table with the column the foreign key will reference referenceColumn: The column in the referenceTable the foreign key will reference
Two functions were added to dialect.go: ForeignKey and ReferentialAction.
Foreign keys are created when the table is created.