Dirk Zander
Dirk Zander

Reputation: 1

PROPEL terms search over muliple columns

I am currently working on a GUI for actions that enables various filters. Among other things, I need a text search across several tables and fields

        PromotionQuery::create()
            .......
            ->innerJoinPromotionLocalizedAttributes()
            ->innerJoinPromotionProduct()
            ->usePromotionProductQuery()
                ->innerJoinPromotionProductLocalizedAttributes()
            ->endUse()
            ->condition('nameInternal', PromotionTableMap::COL_NAME . ' LIKE ?', '%' . $terms . '%')
            ->condition('nameExternal', PromotionLocalizedAttributesTableMap::COL_NAME_EXTERNAL . ' LIKE ?', '%' . $terms . '%')
            ->condition('promotionDescription', PromotionLocalizedAttributesTableMap::COL_DESCRIPTION . ' LIKE ?', '%' . $terms . '%')
            ->condition('productDescription', PromotionProductLocalizedAttributesTableMap::COL_DESCRIPTION . ' LIKE ?', '%' . $terms . '%')
            ->combine(['nameInternal', 'nameExternal', 'promotionDescription', 'productDescription'], Criteria::LOGICAL_OR, 'search')
            ->where(['search']);

I am using Propel 2.0 for this.

But Criteria::combine() seems to incorrectly nest my conditions instead of combining them into a group

SELECT * FROM promotion INNER JOIN promotion_localized_attributes ON (promotion.id_promotion=promotion_localized_attributes.fk_promotion) INNER JOIN promotion_product ON (promotion.id_promotion=promotion_product.fk_promotion) INNER JOIN promotion_product_localized_attributes ON (promotion_product.id_promotion_product=promotion_product_localized_attributes.fk_promotion_product) WHERE promotion.status=1 AND (((promotion.name LIKE '%My Terms%' OR promotion_localized_attributes.name_external LIKE '%My Terms%') OR promotion_localized_attributes.description LIKE '%My Terms%') OR promotion_product_localized_attributes.description LIKE '%My Terms%') LIMIT 1000

I need a query like this (without nested brackets)

SELECT * FROM promotion INNER JOIN promotion_localized_attributes ON (promotion.id_promotion=promotion_localized_attributes.fk_promotion) INNER JOIN promotion_product ON (promotion.id_promotion=promotion_product.fk_promotion) INNER JOIN promotion_product_localized_attributes ON (promotion_product.id_promotion_product=promotion_product_localized_attributes.fk_promotion_product) WHERE promotion.status=1 AND (promotion.name LIKE '%My Terms%' OR promotion_localized_attributes.name_external LIKE '%My Terms%' OR promotion_localized_attributes.description LIKE '%My Terms%' OR promotion_product_localized_attributes.description LIKE '%My Terms%') LIMIT 1000

Upvotes: 0

Views: 26

Answers (0)

Related Questions