Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use of Select() inside custom preloading #1494

Closed
Ganitzsh opened this issue Jun 1, 2017 · 3 comments
Closed

Use of Select() inside custom preloading #1494

Ganitzsh opened this issue Jun 1, 2017 · 3 comments

Comments

@Ganitzsh
Copy link

Ganitzsh commented Jun 1, 2017

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?

@jinzhu
Copy link
Member

jinzhu commented Feb 12, 2018

This should been fixed, thank you for your report.

@jinzhu jinzhu closed this as completed Feb 12, 2018
@jemmycalak
Copy link

i have same problem, is that fixed ?

@djumpen
Copy link

djumpen commented Jan 19, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants