如何使用m2m条件查询数据

Here is the two model with manytomany relationship. Right now I want to query the topic by category name. I know I could achieve this by raw sql like select * from topic where id IN (SELECT topic_id from topic_categories where category_id IN (select id from category where name ILIKE '%tech%'));

The question is, how to do this with gorm in a higher performance and more readable way.

type Category struct {
  Name string
}

type Topic struct {
  Name string
  Categories []*Category `gorm:"manytomany;topic_categories"`
}

I think documentation of GORM is written very well. You can find answer is here http://gorm.io/docs/many_to_many.html Or you can do like this

db.Tabel("topic").Select("*").Where("id IN (SELECT topic_id from topic_categories where category_id IN (select id from category where name ILIKE '%?%'))","tech")