Closed OpenActu closed 3 years ago
The reason is that having an object with a null id doesn't make sense.
The reason is that having an object with a null id doesn't make sense.
Thanks for the response but I don't understand it. When I create a new entity, it's not logic that I first persist my entity and then call the form. Is a process exists to avoid this behavior other than use persist before the createForm ?
Remark : Maybe my remark introduces stability risks and in this case, i could understand why the change of null output is dangerous.
Thanks for the response but I don't understand it. When I create a new entity, it's not logic that I first persist my entity and then call the form. Is a process exists to avoid this behavior other than use persist before the createForm ?
Of course, but the entity you're using for autocomplete is not the new entity: it's an existing entity you're trying to relate with the new one (in your example, you're creating a new Announce and relating it to an existing Customer)
Hi, I solve the issue by changing the __construct() definition for new entity. In fact, the create of new entity inject an announce with null id (see below).
Thanks for your help !
# old definition produced by make:entity
class Announce
{
public function __construct() {
$this->customer = new Customer();
}
}
# new definition
class Announce
{
public function __construct() {
$this->customer = null;
}
}
Hi, I have trouble with the current code. It's very easy to explain.
Here is my controller
Here is my form
When I load the page, I have the error
Return value of PUGX\AutocompleterBundle\Form\Transformer\ObjectToIdTransformer::transform() must be of the type string, null returned
To solve this problem, I only change the return definition into vendor from method PUGX\AutocompleterBundle\Form\Transformer\ObjectToIdTransformer::transform($object): string to to PUGX\AutocompleterBundle\Form\Transformer\ObjectToIdTransformer::transform($object): ?string
After that, not any trouble found.
Can you change it in source, or is it any reason to have transform strictly with string output ?