duanluangua8850 2019-04-13 18:05
浏览 165

找到两个Doctrine集合的交集

I am using Doctrine and have the following SQL tables:

  • entity: id (pk)
  • x_series: id (pk), entity_id (fk references entity.id), name (string), position (int)
  • y_series: id (pk), entity_id (fk references entity.id), name (string), position (int)
  • x_y_intersect: x_series_id/y_series_id (composite pk and fk to x/y_series), name (string)

Given ['entityId'=>123, 'xPosition'=>3, 'yPosition'=>5], I wish to retreive the intercecting object.

One option is to do so using SQL (or DQL) (can be optimized, but written as is for clarity):

SELECT xyi.*
FROM entities e
INNER JOIN x_series xs ON xs.entity_id=e.id
INNER JOIN y_series ys ON ys.entity_id=e.id
INNER JOIN x_y_intersect xyi ON xyi.x_series_id=xs.id AND xyi.y_series_id=ys.id
WHERE e.id=:entityId AND xs.position=:xPosition AND ys.position=:yPosition;

EDIT. Appears that DQL cannot be used as while I didn't mention because I incorrectly felt unimportant, entities is an inherited class and all other inherited classes are left joined.

As an alternative solution, is there a good OOP approach.

$entity=$this->read($id);
$xSeries=$entity->getXseries();
$ySeries=$entity->getYseries();
$xNode=$xSeries->offsetGet($xPosition);
$yNode=$ySeries->offsetGet($yPosition);

//How should this be accomplished?
$intersect=$this->getXYnodeIntersect($entity, $xNode, $yNode);
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
    • ¥15 C# datagridview 单元格显示进度及值
    • ¥15 thinkphp6配合social login单点登录问题
    • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
    • ¥15 如何在scanpy上做差异基因和通路富集?
    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配