简体   繁体   English

Supabase:根据一对多关系中的任何一个是否具有属性来过滤行

[英]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.

相关问题 根据另一个数组的属性过滤一个数组 - Filter one array based on property of another array 如何根据多对一关系过滤 Highchart plot 数据? - How to filter Highchart plot Data based on Many-to-One relationship? 解析javascript一对多关系查询 - Parse javascript one to many relations query 比较反应中的两个数组并根据名称属性的匹配过滤一个数组 - Compare two arrays in react and filter one based on matches of name property 如何根据出现在许多地方的另一个属性对一个JSON属性进行分组? - How to group one JSON property based on one other property that appears at many places? 一种形式的多次插入,用于Laravel中的一对多关系 - Multiple insert in one form, for one-to-many relations in Laravel 根据对象的属性值(相对于其他元素中发生的次数)过滤数组 - Filter array based on an object's property value relative to how many times it occurs in other elements JS-过滤对象数组以查找一个属性的重复项,并根据另一个属性确定要保留的对象 - JS - Filter an array of objects for duplicates of one property, and decide which object to keep based on another property 如何测试Ember模型的具有关系依赖性的计算属性? - How to test an Ember model's computed property that has relations dependencies? Sequelize属于多个在一次查询中获得两种关系 - Sequelize belongs to many get both relations in one query
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM