如何更新窗体中的ManyToOne字段? [英] How do you update ManyToOne field in a form?

查看:150
本文介绍了如何更新窗体中的ManyToOne字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题全部在标题中:)

使用Play!框架2.0,我有一个模型与一个ManyToOne字段到另一个模型。

Using Play! Framework 2.0, I have a Model with a ManyToOne field to an other Model.

在形式中,我显示它与Select id - > toString,提交,我有无效值,因为它期望一个模型的实例(我猜)。

In the form, I show it with a Select id -> toString, but when I hit submit, I've got "Invalid value", because it expect an instance of that Model (I guess).

我该怎么办?

感谢您的帮助!

推荐答案

此选择的名称必须设置为 property.id

Name of this select must be set as property.id

ie。如果你的模型看起来像

ie. if your model looks like

@Entity
public class Entry extends Model {

    @Id
    public Long id;

    public String title;

    @ManyToOne
    public User user;
}    

您的选择应该是这样写的:

Your select should be writen like this:

@select(
    yourForm("user.id"),
    options(User.options),
    'id -> "user",
    '_label -> "Select user"
)

这篇关于如何更新窗体中的ManyToOne字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆