Question

I do this:

$model = ProductQuery::create()
        ->filterById($id)
        ->joinLocale()
        ->joinProducer()
        ->joinCategory()
        ->joinFile()
        ->joinSeo()
        ->find();

This creates the query:

SELECT 
       Food_Product.id,
       Food_Product.locale_id,
       Food_Product.category_id,
       Food_Product.producer_id,
       Food_Product.file_id,
       Food_Product.seo_id,
       Food_Product.customer_id,
       Food_Product.name,
       Food_Product.description,
       Food_Product.nutrient_unit,
       Food_Product.ean,
       Food_Product.top,
       Food_Product.calls,
       Food_Product.visible,
       Food_Product.created_at,
       Food_Product.updated_at,
       Food_Product.created_by,
       Food_Product.updated_by 
FROM `Food_Product` 
INNER JOIN `I18n_Locale` ON (Food_Product.locale_id=I18n_Locale.id) 
LEFT JOIN `Food_Producer` ON (Food_Product.producer_id=Food_Producer.id) 
INNER JOIN `System_Category` ON (Food_Product.category_id=System_Category.id) 
LEFT JOIN `Media_File` ON (Food_Product.file_id=Media_File.id) 
INNER JOIN `System_Seo` ON (Food_Product.seo_id=System_Seo.id) 
WHERE Food_Product.id='1'

I just get a Product Instance without the related data. So if I call $product->getProducer(), there will be another database request.

If I add ->select('*'), I dont get an entity instance anymore, but an array with the product data. But again, there is no producer, locale or category data.

Was it helpful?

Solution

I noticed, that ->joinWith('Producer'). instead of ->joinProducer()works like a charm.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top