I am using the FOSUserBundle and I extended the registration form to input the name of a company when registering a new user. Company
is a separate Entity. I created all required methods for the relation handling.
/**
* User entity
*/
class User {
// ...
addCompany() { /* ... */ }
removeCompany() { /* ... */ }
getCompanies() { /* ... */ }
}
I followed the Symfony guide to embed a Single Object to a form:
class RegistrationFormType extends \FOS\UserBundle\Form\Type\RegistrationFormType
{
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder
->add('...')
->add('company', new CompanyType());
}
// ...
}
The registration form is rendered properly; it shows a field for the Company name. But when I submit, I get
Neither the property "company" nor one of the methods "setCompany()", "_set()" or "_call()" exist and have public access in class "Acme\MyBundle\Entity\User".
I obviously neither don't have a company
property nor a setCompany()
method, because it's a manyToMany relationship, thus I have a companies
property and a addCompany()
method instead.
Questions
- Why doesn't Symfony also look for a
addCompany()
method? - Should I implement a
setCompany()
method (e.g. by simply renaming accordingly, or as a wrapper method which callsaddCompany()
)? - Or is this due to the singular/plural problem which comes up when singular and plural method names can't be interpreted correctly by Symfony?