From 2f5991d088abb922986122ce197d68d85fc5610a Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Tue, 5 Nov 2013 08:08:42 +0800 Subject: [PATCH] Update Document For Related() --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index bfc8c492..8558d4d4 100644 --- a/README.md +++ b/README.md @@ -102,6 +102,8 @@ db.Save(&user) ### Create With SubStruct +Refer [Query With Related](#query-with-related) to find how to find associations + ```go user := User{ Name: "jinzhu", @@ -260,12 +262,15 @@ db.Where("name = 'jinzhu'").Or(map[string]interface{}{"name": "jinzhu 2"}).Find( ### Query With Related ```go +// Find emails from user with guessed foreign key db.Model(&user).Related(&emails) //// SELECT * FROM emails WHERE user_id = 111; +// Find address from user with specified foreign key 'BillingAddressId' db.Model(&user).Related(&address1, "BillingAddressId") //// SELECT * FROM addresses WHERE id = 123; // 123 is the value of user's BillingAddressId +// Find user from email with guessed primary key value from emails db.Model(&email).Related(&user) //// SELECT * FROM users WHERE id = 111; // 111 is the value of email's UserId ```