如何在 Play Framework CRUD 模块中过滤关联
假设我有一个 Cat 类,其中包含小猫的集合。我希望能够根据给定条件列出小猫,例如校长的角色。到目前为止,完全没有问题,我用 @Before 解决了这个问题,它将相应的过滤器添加到列表视图中。
但现在我想更改 Cat 的编辑页面,以便当它列出 Kittens 时(请记住,在编辑视图中我可以选择所选 Cat 的 Kittens),它只带来可用于主体角色的 Kittens。但默认行为是从数据库中检索所有小猫,这不是我想要的。
有谁知道如何实现这一目标?
Let's say I have a Cat class which contains a collection of Kittens. I want to be able to list the Kittens according to a given condition, for example, the principal's role. So far, no problem at all, I resolved this issue with an @Before which adds the corresponding filter to the list view.
But now I want to change the edit page for the Cat, so that when it lists the Kittens (remember, in the edit view I can select the Kittens for the selected Cat), it brings only those available for the principal's role. But the default behavior is to retrieve all the Kittens from the database, and that's not what I want.
Does anyone know how to achieve that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Play 中的默认 CRUD 模块是一个基本的 CRUD,在某些场景下缺乏很多功能。最好的方法是下载模块的代码(您在本地 Play 部署中的“模块”下),将其作为自定义模块添加到您的项目中,并根据需要进行修改。
在您的场景中,只需进入呈现列表视图的部分并修改它即可使用过滤器。
Default CRUD module in Play is a basic CRUD which lacks a lot of functionality in several scenarios. The best approach is to download the code of the module (you have it in your local Play deployment, under "modules"), add it to your project as a custom module and modify it as much as you need.
In your scenario, simply go into the part that renders the List view and hack it to use the filters.