Skip to content

Commit

Permalink
bug: count clear Joins
Browse files Browse the repository at this point in the history
  • Loading branch information
liov committed May 16, 2024
1 parent 4f84925 commit df9f67f
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,35 @@
package main

import "fmt"
type AB struct {
Id int `json:"id" gorm:"primaryKey"`
BId int `json:"aId" gorm:"index"`
AId int `json:"bId" gorm:"index"`
B B `json:"b"`
A A `json:"a"`
}

type A struct {
Id int `json:"id" gorm:"primaryKey"`
Name string `json:"name" gorm:"uniqueIndex"`
}

type B struct {
Id int `json:"id" gorm:"primaryKey"`
Name string `json:"name" gorm:"uniqueIndex"`
}

func main() {
fmt.Println("vim-go")

DB.Migrator().DropTable(&AB{}, &A{}, &B{})
DB.Migrator().CreateTable(&AB{}, &A{}, &B{})
var (
count int64
appNodes = []*AB{}
)
db := DB.Model(&AB{}).Preload("A").Joins("B").Where(`id = ?`, 11)

db.Count(&count)

db.Limit(1).Offset(0).Order("id DESC").Find(&appNodes)

}

0 comments on commit df9f67f

Please sign in to comment.