I'm still new in Symfony and I'm trying something (I think) common.
I've some entities: product, theme, event, with one to many and many to one connection; so I've other entities called products_in_theme, products_in_event. A theme is a type of party, that use some kind of products (like colors, paper, etc). When I made an event, I need all or some of that products, and I need to save that products in products_in_event. With CraueFormFlowBundle I've created the form (step1: select theme and date, step2: select products). The problem is that: I need to show in an EntityType "Product in Event" (in order to persist that), values from "Product In Theme". The query doesn't work because is looking from "product in event" instead only "product in theme"
public function buildForm(FormBuilderInterface $builder, array $options)
{
$theme= $options['theme'];
$builder
->add('products', EntityType::class, array(
'class' => 'AppBundle\Entity\ProductInEvent',
'expanded'=>'true',
'multiple' => 'true',
'query_builder' => function (EntityRepository $er) use ($theme){
return $er->createQueryBuilder('product_in_event')
->from('AppBundle:ProductInTheme', 'product_in_theme')
->where('product_in_theme.theme = :theme')
->setParameter('theme', $theme);
}
));
}
The query is:
SELECT p0_.id AS id_0, p0_.price AS price_1, p0_.event_id AS event_id_2, p0_.product_id AS product_id_3
FROM product_in_event p0_, product_in_theme p1_
WHERE p1_.theme_id = 27;`
which returns 0 entries (because product_in_event is empty)
Update 2015/02/01
I've some entities:
Product:
-Id, Name, quantity, price
Event:
Id, Name, Products (mapped by product_id in product_in_event)
Product_In_Event:
Id, Event_id, Product_id (inversed by products in Event)
Theme
Id, Name, Products (mapped by theme_id)
Product_in_theme:
Id, Product_id, Theme_id (inversed by products in theme)
It's a common connection: A product in event have some FK related to Event and Product.
You can view the situation like: Categories and Products. When you buy something, the "product_in_category" became "product_in_order"