1

I'm actually facing an issue onto Symfony 4.1.6, where i'm trying to build 2 CRUD for 2 different classes.

Let's say :

- Jobs - Categories

Jobs tables has an id_category, so it's a ManyToOne relationnal field to the Categories Table.

I've generated theses entities.

Just after this (and migrations of course), i'm doing a php bin/console make:crud, to build the CRUD of theses classes. Everything works for now.

The problem is when i create a new category, from the new auto-generated form, i'm facing an error when i go back on jobs and try to add one :

Catchable Fatal Error: Object of class App\Entity\Category could not be converted to string

I precise that until i create a category from the form, everything seems to work well...

What am i missing here ? Is it a bug ?

Thanks a lot in advance for your help,

Have a productive night,

Brawcks

Vincent Cfn
  • 87
  • 1
  • 9
  • Possible duplicate of [symfony2 Catchable Fatal Error: Object of class could not be converted to string](https://stackoverflow.com/questions/28710085/symfony2-catchable-fatal-error-object-of-class-could-not-be-converted-to-string) – mblaettermann Oct 18 '18 at 02:03

1 Answers1

0

The simplest way would be adding àn public __toString() method to your Category entity.

The return value of that method will be used for the descriptive Label in the generated <option value="id">Categoryname</option>

mblaettermann
  • 1,916
  • 2
  • 17
  • 23
  • Oh okay ! Thanks, 'im gonna try it at home ! So actually the make:crud do not support relationnal fields ? – Vincent Cfn Oct 18 '18 at 09:13
  • make:crud cannot know which property to use. Maybe it could be extended to "guess" by looking for properties like name, title, label and use these by default in the maker bundle. – mblaettermann Oct 19 '18 at 10:09