Здравствуйте!
У меня есть 2 сущности Category и Product.
Они связаны таким образом:
У категории может быть множество товаров(OneToMany)
У товара может быть только 1 категория(ManyToOne)
Я столкнулся с такой проблемой - при получении товара из базы происходит зацикливание запроса
public function search($data)
{
$qb = $this->createQueryBuilder("p")
->select('p')
->where("p.id1c = :data")
->setParameter("data", $data);
$products = $qb->getQuery()
->getResult();
return $products;
}
В логи пишется 2 запроса:
[2016-09-20 01:28:20] doctrine.DEBUG: SELECT p0_.id AS id_0, p0_.id1c AS id1c_1, p0_.status AS status_2, p0_.limit_sales AS limit_sales_3, p0_.type_of_products AS type_of_products_4, p0_.name AS name_5, p0_.code AS code_6, p0_.description AS description_7, p0_.handler AS handler_8, p0_.art AS art_9, p0_.price AS price_10, p0_.price_retail AS price_retail_11, p0_.image AS image_12, p0_.image_width AS image_width_13, p0_.image_height AS image_height_14, p0_.image_big AS image_big_15, p0_.image_big_width AS image_big_width_16, p0_.image_big_height AS image_big_height_17, p0_.sort AS sort_18, p0_.date_updated AS date_updated_19, p0_.date_created AS date_created_20, p0_.category_id AS category_id_21, p0_.exchange_rate_setting_id AS exchange_rate_setting_id_22 FROM `product` p0_ WHERE p0_.id1c = ? ["00000082457"] []
[2016-09-20 01:28:20] doctrine.DEBUG: SELECT t0.id AS id_1, t0.id1c AS id1c_2, t0.parent_id1c AS parent_id1c_3, t0.code AS code_4, t0.name AS name_5, t0.description AS description_6, t0.description2 AS description2_7, t0.title AS title_8, t0.meta_h1 AS meta_h1_9, t0.meta_description AS meta_description_10, t0.retail_limit AS retail_limit_11, t0.limit_sales AS limit_sales_12, t0.type_of_products AS type_of_products_13, t0.show_retail_price AS show_retail_price_14, t0.ueprice AS ueprice_15, t0.status AS status_16, t0.sort AS sort_17, t0.parent_id AS parent_id_18 FROM category t0 WHERE t0.id = ? [1621] []
Как я понимаю ситуация такая:
1. Доктрина достает товар
2. После чего достает категории товара
3. Получает все товары категории
А искомый товар находится в п.3 и все заного.
Каким образом можно избежать проблемы такого зацикливания?
Как можно достать объект товара не подгружая связанную категорию