Answer the question
In order to leave comments, you need to log in
How to implement such a relationship in Symfony (and display it on the entity form)?
Hello!
Question on Doctrine and Symphony.
It is necessary to make the following mechanism of links in the application:
1) There is a product group entity
2) There is a product parameter entity
3) There is a product entity
There are the following links:
- The product is linked to the Product group (Many-to-one, links are stored in the special field of the Product)
- The product parameter is linked to the Product group (Many-to-many, links are stored in a separate table)
. Thus, the Product parameters are not explicitly related to the Product entity. Parameters and Products are linked through the parent Product Group of a particular product.
What is required is this: when creating/editing a product, the form should display all the Product Parameters linked to the parent Product Group of this Product. And how to store parameter values for each individual product?
How to implement this, gentlemen? (sorry for the goods goods goods goods...)
Answer the question
In order to leave comments, you need to log in
Well, first of all, it is the task of the client. Ideally, you should have 2 forms, not just one.
Without client intervention, you can solve this problem with two submit buttons.
If js works, then either through 2 submits, or through one form, where a Parameter is added to the Product with the mapping turned off using the listener.
1.
The form is sent with an additional button, the same js when changing the Product group.
// ProductGodType
$form->get('nextStep')->isClicked() {
// add Parameters
}
// PtoductType
$builder->add('parameters', 'choice', [
'data' => $options['parameters'],
'mapped' => false,
//...
}
{
"name" : "ProductName",
"group" : {
"parameters" : [
// ...
],
}
if ($this->isXmlHttpRequest()) $this->get('validator')->validate($object);
) and, if successful, save it to the database. + One more parameter entity for each individual product:
"product id"
field "parameter id (from 2 p.)"
field "parameter value " field
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question