php - Symfony - 用另一个实体的 id 重载实体集函数
问题描述
根据另一个实体的字段重载一个实体的集合函数是否可行且可行。
我在表 1(E 列)中有一个字段,它将由 C 列或 D 列组成(它搞砸了 2 个字段具有相同的字段,但它会在另一个时间,我只是试图使这个工作)。字段 E 将取决于另一个表 (2)。
示例:如果在表 2 中,字段“crit1”或“crit2”是“localisation”,在表 1 中,“tri_id”列(F 列)将取 D 列的值,否则取 E 列的值。
这些表的结构示例
=> adapte_gaucher 的意思是“左撇子适应”
我在我的实体中这样做:
/**
* @param int $triId
*/
public function setTriId(int $shopId, int $triId): void
{
$entityManager = $this->getDoctrine()->getManager();
$products = $this->getDoctrine()
->getRepository(Table1::class)
->find($shopId)
if(Table1->crit1 != "localisation" || Table1->crit2 != "localisation" ) {
$triId = $this->tri21 ;
} else {
$triId = $this->tri12 ;
}
$this->triId = $triId;
$entityManager->persist($triId);
$entityManager->flush();
}
这会是一个好的解决方案吗?我太新了,不知道这是否是一个好方法,或者我是否不应该这样做。这是我的实习项目(我只是一名大三学生,在我身后只进行了一年的编程,没有任何框架课程)。对不起,“悲怆”的台词,但它真的会帮助我成功。
不管怎么说,还是要谢谢你。
解决方案
尽管“IF”的想法并不明智,但我想尝试一个简单的连接,但是:
public function setTri12()
{
$this->tri12 = $shop_id . $pack_id . $adapte_gaucher_id;
return $this;
}
或者 :
public function setTri12()
{
$this->tri12 = $this->shop_id . $this->pack_id . $this->adapte_gaucher_id;
return $this;
}
两者都返回一个空值,因为这 3 个值都是空的。
我可以强迫它吗?谢谢
推荐阅读
- android - Android Studio 卡在 gradle 同步
- sql - 两个实例中相同数据库上的执行计划不同
- c# - OnCollisionStay 和协程问题
- c# - 加载新场景后 Unity Photon Network CustomPropeties 未更新
- python-3.x - python - 如何根据Python中的条件对列表进行结构迭代?
- html - CSS中的大单选按钮设计
- r - 缩放散点图的 X 和 Y 轴以填充整个轴
- lotus-notes - 是否可以在 Lotus Notes 客户端中“捕获”发送邮件功能?
- reactjs - 无法在显示错误且我无法理解的 ubuntu 中安装 react?
- react-native - 使用 fetch 'get' 方法给 cookie。[反应原生]