
Is it okay and feasible to overload a set function of an entity according to a field from another entity.
I have a field in table 1 (column E) which would consist of either column C or D (it’s messed up to have 2 fields with the same field but it would be in another time, I just try to make this works).
The field E would depends on another table (2).
Example: If in table 2, fields "crit1" ou "crit2" are "localisation",in table 1, the column "tri_id" (column F) would take value of column D otherwise the value of column E.
example of structure of these tables
=> adapte_gaucher means "left-handed adapted"
I was doing this in my entity:
/**
* @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();
}
Would this would be an okay solution? I am too new to know if that’s a good method or if I should never do that.
It’s my internship project (I am just a junior and just get a year of programming behind me and without any framework course).
Sorry for the "pathos" lines but it would really help me to succeed it.
Thanks anyway.
Source: Symfony Questions
Was this helpful?
0 / 0