gpt4 book ai didi

symfony - 多对多和奏鸣曲管理捆绑

转载 作者:行者123 更新时间:2023-12-04 03:38:19 25 4
gpt4 key购买 nike

我有ManyToMany相关实体Partner和District,但是当我编辑实体对象之间的关系时,不会保存更改。

实体区

class District
{
...
/**
* @ORM\ManyToMany(targetEntity="Partner", inversedBy="districts")
* @ORM\JoinTable(name="thedo_pcsuppurt_districts_partners",
* joinColumns={
* @ORM\JoinColumn(name="district_id", referencedColumnName="id")
* },
* inverseJoinColumns={
* @ORM\JoinColumn(name="partner_id", referencedColumnName="id")
* }
* )
*/
private $partners;
...

实体合作伙伴
class Partner
{
...
/**
* @ORM\ManyToMany(targetEntity="District", mappedBy="partners")
* @ORM\OrderBy({"name" = "ASC"})
*/
private $districts;
...

管理员类
class PartnerAdmin extends Admin
{
public function configureFormFields(FormMapper $formMapper)
{
$formMapper
->with('General')
->add('name', null, array('label' => 'name'))
->add('mail', null, array('label' => 'mail'))
->add('ticket_prefix', null, array('label' => 'Ticket Prefix'))
->end()
->with('Districts', array('collapsed' => true))
->add('districts', null, array('label' => 'Districts', 'expanded' => true, 'by_reference' => false, 'multiple' => true))
->end()
;
}
...

我没有任何错误,但是重新加载页面时不保存关系。

UPD 在我的日志中,我看到了
[2013-10-03 10:09:19] doctrine.DEBUG: SELECT t0.id AS id1, t0.name AS name2, t0.mail AS mail3, t0.login AS login4, t0.password AS password5, t0.ticket_prefix AS ticket_prefix6, t0.created_at AS created_at7, t0.updated_at AS updated_at8 FROM thedo_pcsupport_partner t0 WHERE t0.id = ? ["1"] []
[2013-10-03 10:09:19] doctrine.DEBUG: SELECT t0.id AS id1, t0.name AS name2, t0.city_id AS city_id3 FROM thedo_pcsupport_district t0 [] []
[2013-10-03 10:09:19] doctrine.DEBUG: SELECT t0.id AS id1, t0.name AS name2, t0.city_id AS city_id3 FROM thedo_pcsupport_district t0 INNER JOIN thedo_pcsuppurt_districts_partners ON t0.id = thedo_pcsuppurt_districts_partners.district_id WHERE thedo_pcsuppurt_districts_partners.partner_id = ? ORDER BY t0.name ASC [1] []

最佳答案

您可以在cascade={"persist"}批注上尝试@ORM\ManyToMany吗?

除此之外,请确保您具有如下所示的加法器:

// District.php

public function addPartner($partner)
{
$this->partners[] = $partner;
$partner->setDistrict($this); // This line is important for Sonata.
}

我希望您知道,可以使用 doctrine:generate:entities(而不是 doctrine:generate:entity)轻松生成此类加法器(和移除器)。

关于symfony - 多对多和奏鸣曲管理捆绑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19138775/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com