Context: Let's say that I've got 3 models in a sailsJS app talking to a PostGres backend via waterline: artist, song and rating. The artist contains a collection of songs, the songs contain a collection of ratings. Simple, yes?
Problem: I want to be able to query on the song and have it populate the list of artists with ratings that go along with that. So I might do something like this:
ratings:[4,2,1]
songs:[1,4,5]
where each rating is the id of the object that I created before and each song is the id of the song object in the association.
That way, on the client, I can go in, find the index on both the ratings and songs arrays, and know that I've got rating 4 on song 1, rating 2 on song 4, etc. But when I do that, it seems that Waterline re-orders the objects in the association from low-to-high based on the id. So when I call the endpoint, I get this:
ratings:[1,2,4]
songs:[1,4,5]
Thereby breaking the relationship between the different arrays.
I think this is probably a commmon use case and I'm missing something basic...what is it? A parameter setting on waterline?
Or is there a better way to do this?
我从来没有找到答案,但是最终我重构了模型以实现关联中更高层次的抽象。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.