Answer the question
In order to leave comments, you need to log in
Compose complex queries based on Propel (ORM)
I will be very glad if someone will explain to me how to create complex structures in this very "propeller".
Task:
Add to an existing model, query part
$products = \SProductsQuery::create()
->joinWithI18n(\MY_Controller::getCurrentLocale())
->leftJoin('ProductVariant')
->joinMainCategory()
->where('MainCategory.Active = ?', 1)
->orderBy('ProductVariant.Stock', 'DESC')
->distinct()
->filterByActive(true);
//....тут пропущен некоторый участок кода - различные условия и проверки .....
$products = $products
->useI18nQuery(\MY_Controller::getCurrentLocale())
->filterByName('%' . $search_str . '%')
->endUse();
$products = $products->orWhere('ProductVariant.Number LIKE ?', '%' . $search_str . '%');
$products = $products->orWhere('SProducts.Id LIKE ?', $search_str);
OR WHERE (SProductsI18n.NAME LIKE = '$someString' AND SProductsI18n.NAME LIKE '$oneMoreString')
$stringArr = array($someString, $oneMoreString);
$products = $products->orWhere('SProductsI18n.Name LIKE ? AND SProductsI18n.Name LIKE ?', $stringArr);
Answer the question
In order to leave comments, you need to log in
Do not suffer, write a couple of lines of human SQL. It is clear that you want beautifully, that's all, but sometimes it's easier to write the good old SQL.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question