pg icon indicating copy to clipboard operation
pg copied to clipboard

How to write your own join query on associations

Open sonhnguyenn opened this issue 4 years ago • 0 comments

Will I be able to make my own Joins query and somehow go-pg can map the fields to the corresponding model?

			err := ecrawler.DB2.Model(&products).
				Column("product.*").
				Joins("variants on ....").
				Joins("options on ...").
				Joins("attributes on ...").
				Joins("attribute_values on ....").
				Where("product.id IN (?)", gopg.In(chunk)).
				Select()

I tried but my products having empty associations (products[0].Variants = nil, products[0].Attributes = nil)

sonhnguyenn avatar Mar 30 '20 13:03 sonhnguyenn