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

easonlin404 picture easonlin404  路  3Comments

rfyiamcool picture rfyiamcool  路  3Comments

satb picture satb  路  3Comments

pjebs picture pjebs  路  3Comments

sredxny picture sredxny  路  3Comments