【问题标题】:Sonata Admin, dependant child fieldsSonata Admin,从属子字段
【发布时间】:2015-11-20 06:13:14
【问题描述】:

我有三个班级,

OrderAdminProductAdminOrderHasEquipmentAdmin

Order 需要将与该产品相关的ProductEquipment 添加到中间表OrderHasEquipment 中。

我可以添加新产品,但是当我尝试添加 OrderHasEquipment 时,它会显示我在数据库中拥有的所有设备,我只想显示该产品可用的设备并附加到该订单。

关系是

订单 -> manyToOne -> 产品

Order -> oneToMany -> OrderHasEquipment (因为我需要一个中间实体来与奏鸣曲管理员sonata_type_collectionsonata_type_model_list 合作)

产品 -> manyToMany -> 设备

So, when creating/editing an Order, it shows up a choice list with Products, I need a behaviour that when a Product is selected, OrderHasEquipment (that is a sonata_type_collection field sonata_type_model_list 里面是中间实体),请允许我只添加一个与所选 Product 相关的 Equipment 项目。

有什么办法吗?

【问题讨论】:

  • 你用过->with('Relation table')吗?
  • 现在,我试图使用孩子和父母的东西,但没有像预期的那样工作。 ->with('Relation table') 的东西怎么样?
  • 您为 OrderHasEquipment 设置了所有正确的关系吗?
  • 是的,关系正确,表格运行良好,我只想显示所选产品的设备并将它们分配给订单,这是我不知道如何实现的工作流程。跨度>

标签: php symfony sonata-admin


【解决方案1】:

如果所有关系都正确:

protected function configureDatagridFilters(DatagridMapper $datagridMapper)
    {
        $datagridMapper
            ->add('Equipment') //name from Entity
        ;
    }

【讨论】:

  • 好吧,你之前说->with('Equipment'),现在add,正如我所说,我可以正确添加表单字段,没有问题,使用->add(Equipment) 我不能做(因为不知道如何)是只获取与Order 内的Product 相关的该字段的元素。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-04-12
  • 2017-12-15
  • 2018-07-20
  • 1970-01-01
  • 1970-01-01
  • 2012-02-09
  • 2018-07-11
相关资源
最近更新 更多