duanmi1900 2013-09-16 20:44
浏览 104
已采纳

Doctrine多对一关联不断从关联表中提取所有行

I'm attempting to set up a many-to-one relationship between a series of sales memos and transaction records.

/**
 * @var TransactionInterface
 *
 * @ORM\ManyToOne(targetEntity="Twb\Common\Model\Broker\TransactionInterface")
 * @ORM\JoinColumn(name="FormNoSeller", referencedColumnName="Form")
 */
private $formnoseller;

/**
 * @var TransactionInterface
 *
 * @ORM\ManyToOne(targetEntity="Twb\Common\Model\Broker\TransactionInterface")
 * @ORM\JoinColumn(name="FormNoBuyer", referencedColumnName="Form")
 */
private $formnobuyer;

They are split between two different bundles at the moment ('SalesBundle' and 'BrokerBundle'), and with that in mind I am using interfaces from the SalesMemo entity in SalesBundle to the Transaction entity in BrokerBundle.

For some reason, when I reference either or both of $formnoseller and $formnobuyer in my forms, I notice in dev.log that, after selecting all Transaction rows matching the $formnoseller and/or $formnobuyer fields in the SalesMemos, Doctrine tries to SELECT all rows in the Transaction table (the entity for which TransactionInterface references). This is a bit of a problem, since there is an innumerable amount of rows in the DB, which takes up a lot of memory.

Is there any way to have Doctrine avoid selecting all rows with associations? Or am I even understanding properly how Doctrine does associations? Many thanks for any help.

  • 写回答

2条回答 默认 最新

  • dousi1097 2013-09-17 07:00
    关注

    My understanding of your problem is that you're using an Entity Field Type for $formnoseller and $formnobuyer (or you don't specify the type). Giving the choice to select any élément from the underlying table is the expected behaviour for the Entity Field Type (Used by default for OneToMany relationships)

    If you don't whant a select list of all the elements of your table for those Fields, you should use an other form field type. You should also have a look at data transformers in the documentation.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘