2017-07-20 13:53
浏览 27


I have this query that works fine on mysql and return the intended result, but sqlx has difficulty to handle it:

var jokes []model.Joke
err := shared.Dbmap.Select(&jokes, "SELECT * FROM joke INNER JOIN jokevote ON joke.id=jokevote.joke_id AND jokevote.vote=? AND joke.user_id=?", 1, userId)
if err != nil {

At runtime, I get no result but this error message in terminal:

missing destination name joke_id

I don't have this issue when querying a single table.

So I'm wondering what is wrong here and how to fix it?

UPDATE: Here are the structs:

type Joke struct {
    ID         int       `db:"id" json:"id"`
    UserID     int       `db:"user_id" json:"user_id"`
    Title      string    `db:"title" json:"title"`
    Content    string    `db:"content" json:"content"`


type JokeVote struct {
    ID     int `db:"id" json:"id"`
    JokeID int `db:"joke_id" json:"joke_id"`
    UserID int `db:"user_id" json:"user_id"`
    Vote   int `db:"vote" json:"vote"`
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题