[英]Loopback filter using related model field
Imagine we have two tables, session
and movie
in postgresql. 想象一下,在PostgreSQL中有两个表,
session
和movie
。 The table session
has a foreignkey to movie
. 表
session
有movie
。 How can i define a relation in movie
so that i can ask for movies with filters on session
. 我如何在
movie
定义一个关系,以便我可以在session
请求带有过滤器的电影。 This table, for example, has a column created
and i want to ask for results that has sessions after today with a custom method in Movies.js. 例如,此表有一个
created
的列,我想用Movies.js中的自定义方法来查询今天以后有会话的结果。
The table session has a foreignkey to movie, then you can define relations on both models(use a custom foreign key if necessary). 表会话具有电影的外键,然后可以在两个模型上定义关系(必要时使用自定义外键)。 Then, you can simply query data through the relation you have already defined.
然后,您可以简单地通过已定义的关系查询数据。 just use
find
, include
, scope
and where
to get the data you want. 只需使用
find
, include
, scope
以及从where
获取所需数据即可。 If you can paste your json files for both models, it will be easy to figure it out. 如果您可以为两个模型粘贴json文件,则很容易弄清楚。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.