R
R
Roman Sokharev2014-05-08 06:55:12
PHP
Roman Sokharev, 2014-05-08 06:55:12

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);

And after that I need to add one more condition, like:
OR WHERE (SProductsI18n.NAME LIKE = '$someString' AND SProductsI18n.NAME LIKE '$oneMoreString')

Kill, but I can not understand how it is done on the propeller.
Tried to work as with PDO - to betray an array.
$stringArr = array($someString, $oneMoreString);
 $products = $products->orWhere('SProductsI18n.Name LIKE ? AND SProductsI18n.Name LIKE ?', $stringArr);

Something doesn't work. Tried to understand how this Propel works. But at the fifth level of inheritance - the head is spinning.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nazar Mokrinsky, 2014-05-08
@nazarpc

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 question

Ask a Question

731 491 924 answers to any question