From 7e8c0f7edddfb9d8782e4c0d430e5574df23f34f Mon Sep 17 00:00:00 2001 From: jnfeinstein Date: Tue, 25 Nov 2014 21:22:31 -0800 Subject: [PATCH] Add README.md updates for polymorphism. --- README.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/README.md b/README.md index 8a5cfb0f..4ad61e2f 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ The fantastic ORM library for Golang, aims to be developer friendly. * Iteration Support via [Rows](#row--rows) * Scopes * sql.Scanner support +* Polymorphism * Every feature comes with tests * Convention Over Configuration * Developer Friendly @@ -507,6 +508,32 @@ db.Model(&user).Association("Languages").Clear() // Remove all relations between the user and languages ``` +### Polymorphism + +Supports polymorphic has-many and has-one associations. + +```go + type Cat struct { + Id int + Name string + Toy Toy `gorm:"polymorphic:Owner;"` + } + + type Dog struct { + Id int + Name string + Toy Toy `gorm:"polymorphic:Owner;"` + } + + type Toy struct { + Id int + Name string + OwnerId int + OwnerType int + } +``` +Note: polymorphic belongs-to and many-to-many are explicitly NOT supported, and will throw errors. + ## Advanced Usage ## FirstOrInit