ManyToMany Ebean 映射在 View 中不起作用

ManyToMany Ebean mapping not working from View

大家好,

我有 2 个模型(Products 和 ProductCategory),它们在多对多关系中相互关联。但是,当我尝试保存包含应该映射到 ProductCategory 的 html select 字段的产品表单时,我得到一个

{"product_categories":["Invalid value"]}

我的模特是

Products.class
  public class Products extends Model{
    @ManyToOne
    public ProductCategories product_categories;
    ........Other methods and variables
  } 



ProductCategories.class
  public class ProductCategories extends Model
     @OneToMany(cascade = CascadeType.ALL, mappedBy = "product_categories")
     public List<Products> product = new ArrayList<>();
     ..........othee methods and variables
  }

景色是这样的

<select name="product_categories" class="form-control required">
     @for(prodCategory <- productCategories){
        <optionvalue="@prodCategory.getId()">@prodCategory.getCategory_name()</option>
} 
</select>

我实际上还更新了两个模型之间的 OneToMany 关系,并且收到了相同的错误消息。我也试过我在 Google 的一些 post 上看到的,我应该在视图中放一个 [],比如

<select name="product_categories[]" class="form-control required"> 这是同一个问题。我可以使用 request().body().asFormUrlEncoded()

确认视图正在将所有数据从视图发送回控制器

请问有人知道让映射起作用的方法吗?

感谢@singhakash 指出他自己的 post 有类似问题。我注意到他的视图名称包括 .id 例如我使用 product_categories 作为 select 名称他使用 product_categories.id 在我将我的名称更改为它使用他的步骤后his post 中概述。如果没有那个改变,我就无法超越验证步骤。