Symfony2 Sonata Admin sonata_type_collection inline editing hidden field

Here I've found the answer to my simple question: How to inline edit a dependend one to many field without showing the parent as select box.

http://www.obverse.com/2013/05/working-with-the-sonata-admin-bundle-and-sonata_type_collection/


Here is a brief answer: Use prePersist / preUpdate methods in ParentAdmin.php class.
// in the ParentAdmin class


public function prePersist($promotion)
{
foreach ($promotion->getRules() as $rule) {
$rule->setPromotion($promotion);
}
}

public function preUpdate($promotion)
{
foreach ($promotion->getRules() as $rule) {
$rule->setPromotion($promotion);
}
$promotion->setRules($promotion->getRules());
}

Yes indeed, the sonata admin class allows for prePersist and preUpdate calls that allows us to set the promotion for the rule before persisting. Of course don’t forget to declare your admin classes as services in your configs. Other than that, I hope that this helps somebody out there.