[英]Supabase: filter rows based on if any of their one to many relations has property
In supabase I have a list of tracks and each track can have multiple artists (kept in a separate table).在 supbase 中,我有一个曲目列表,每个曲目可以有多个艺术家(保存在单独的表格中)。 I only want tracks in which at least one of the artists associated with that track contains a certain property, we'll say their genre has to equal rap.我只想要其中至少一个与该曲目相关的艺术家包含特定属性的曲目,我们会说他们的流派必须等于说唱。
tracksWithAtLeast1ArtistWhoseGenreIsRap = await supabase
.from("tracks")
.select("name, artists ( genre ), id")
.filter("artists.genre", "eq", "rap")
here is what i'm workin right right now but the issue is that I think this filters the selected artists within each track by genre rather than filtering the tracks based on if any of its artists has the genre "rap".这就是我现在正在做的事情,但问题是我认为这会按流派过滤每首曲目中选定的艺术家,而不是根据其艺术家是否有流派“说唱”来过滤曲目。
You can use the !inner
keyword to filter your top level table (tracks) by its relational table (artists).您可以使用!inner
关键字按关系表(艺术家)过滤顶级表(曲目)。
In the docs, it says在文档中,它说
If you want to filter a table based on a child table's values you can use the !inner() function.如果要根据子表的值过滤表,可以使用 !inner() 函数。 For example, if you wanted to select all rows in a message table which belong to a user with the username "Jane":例如,如果您想选择消息表中属于用户名为“Jane”的用户的所有行:
In your case, the query could look like this:在您的情况下,查询可能如下所示:
tracksWithAtLeast1ArtistWhoseGenreIsRap = await supabase
.from("tracks")
.select("name, artists!inner( genre ), id")
.eq("artists.genre", "rap")
You can read more about !inner
in our documentation here !您可以在我们的文档中阅读更多关于!inner
的信息!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.