Gorm: Use of Select() inside custom preloading

Created on 1 Jun 2017  ·  3Comments  ·  Source: go-gorm/gorm

Hi,

I was trying to do the following:

type A struct {
  Foo string
  Bar int
  Bs []B `gorm:"many2many:a_b`
}

type B struct {
  Field string
  As A[] `gorm:"many2many:a_b`
}

...

db.Preload("As", func(db *gorm.DB) *gorm.DB {
  return db.Select("foo").Order("bar ASC")
}).First(&B{})

But the query that is executed is

SELECT * FROM "as" .... ORDER BY bar ASC

Obviously custom preloading doesn't handle Select() when retrieving a many2many association.

Is it wanted?

Most helpful comment

This should been fixed, thank you for your report.

All 3 comments

This should been fixed, thank you for your report.

i have same problem, is that fixed ?

@jinzhu Faced with same problem, Select() is not working properly for m2m associations.
I am using m2m and 1toM connections at the same time

Was this page helpful?
0 / 5 - 0 ratings

Related issues

koalacxr picture koalacxr  ·  3Comments

rfyiamcool picture rfyiamcool  ·  3Comments

satb picture satb  ·  3Comments

alanyuen picture alanyuen  ·  3Comments

easonlin404 picture easonlin404  ·  3Comments