I got 2 entities linked by a 'OneToMany' relationship.
One of the entities is the object City
. The table corresponding to this object includes almost 37000 entries.
When I proceed to the creation of a form to populate the Proprietairy entity in Symfony, I use a FormType which looks like below. It includes a field corresponding to the City Object
namespace Immo\BienBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilder;
class ProprietaireType extends AbstractType {
public function buildForm(FormBuilder $builder, array $options) {
$builder
->add('nom')
->add('prenom')
->add('email')
->add('telephone')
->add('adresse')
->add('city', 'entity', array(
'class'=>'Immo\BienBundle\Entity\City',
'property'=>'city'));
}
public function getName() {
return 'immo_bienbundle_proprietairetype';
}
}
The form renders a combobox. populated by the 36000 cities and takes incredibly long to load. I have tried the option fetch="extra_lazy", but it is still not efficient enough. My idea was to create a form with an input field working with ajax and displaying the list of the cities after the user provides 2 letters. I would appreciate any help from the community to create the needed relationship with my Object when validating.
Use https://github.com/symfony/symfony/pull/1951 Soon in the v2.1 I hope...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With