I have a user class that has a onetomany self-referencing relationship (ancestor and decendents). And I have an invoice class, which references two users based on the ancestor-decendents relationship. Meaning that, a user creates an invoice, so the form's "from" property will have the logged in user, while the form's "to" property should be a selection from the logged in user's decendets. This is the invoice's buildForm method
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('createdDate')
->add('from')
->add('to', 'entity', array('class' => 'Disty\SystemBundle\Entity\User'))
;
}
To keep it short, I want to somehow only show options of decendent users. Right now it shows all users registered.
答案 0 :(得分:2)
You should take a look at the query_builder parameter that should do the trick.
答案 1 :(得分:2)
If you look at the documentation you can find query_builder
option of the entity
form type. So you just need to modify query builder to retrieve only users which belong to the current logged in user.