Skip to content

Instantly share code, notes, and snippets.

@metalmatze metalmatze/gorm-join.go Secret
Created Mar 22, 2016

What would you like to do?
Scan gorm join resulsts with nested objects
type Post struct {
ID int
Title string
Date time.Time
type User struct {
Name string
Post Post
func query() {
var users []User
Select(",, post.title").
Joins(`LEFT JOIN posts AS post
ON id = (
SELECT id FROM posts WHERE user_id = id ORDER BY date DESC LIMIT 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.