Answer the question
In order to leave comments, you need to log in
Not a simple SELECT * FROM, right?
Help with the request, I’ve already broken my head, if it’s difficult - where to look, where to read the article, I absolutely don’t understand how to make such a request:
There are models:
User {
ID uint
Name string
}
Fruit {
ID uint
Name string
Similar []*Fruit // many2many
}
RateFruit {
UserID uint
User User // has one
FruitID uint
Fruit Fruit // has one
IsLiked bool
}
Answer the question
In order to leave comments, you need to log in
for many-to-many relationships, one more table is needed.
The edge of the graph of connectivity A, B (key1, key2)
here or in the base to put as two vectors AB and BA
requests for sampling is easier
or once. the base is smaller, but then jogging queries key1 and key2 Join the
rating table (A) with the table of analogues by key1=A.fruit_id
left outer join with the rating table (B) by key2 = B.fruit_id
where A.user rated and B.user null
From the query above, the id of the frks will be known. Now connect with the table of frks itself to reveal the names.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question