Grouping conditions in an ORM Propel query (condition, combine) / ~#root -i Grouping conditions in an ORM Propel query (condition, combine) / ~#root -i Grouping conditions in an ORM Propel query (condition, combine) / ~#root -i Grouping conditions in an ORM Propel query (condition, combine) / ~#root -i Grouping conditions in an ORM Propel query (condition, combine) / ~#root -i Grouping conditions in an ORM Propel query (condition, combine) / ~#root -i Grouping conditions in an ORM Propel query (condition, combine) / ~#root -i Grouping conditions in an ORM Propel query (condition, combine) / ~#root -i
  • RU
  • UA
  • EN
  • Create an online store
  • Documentation
  • Blog
    • Unix ОS
    • Php
    • MySQL
    • JavaScript
    • Package Managers
    • Docker
    • Seo
  • Auxiliary services
    • Short Links
    • Exchange views YouTube
  • Sign in
  • Create Account
  • Home
  • Php
  • Grouping conditions in an ORM Propel query (condition, combine)

Grouping conditions in an ORM Propel query (condition, combine)

It is often necessary to combine conditions in a query. If this is easy to do in SQL, then using the ORM you have to reinvent the wheel. ORM Propel allows you to do this without a crutch through the tools ->condition() and ->combine().

Let's look at a complex example so that we can extract a lot of useful things from it.

For example, we need to insert the following condition in WHERE:

There are products that you need to select from the category according to this principle.

(A && B && C) OR D

A - (user) - User who created the product.

B - (price) - item price

С - (stock) - quantity of goods

D - (ignore) - flag responsible for "output anyway"

Implementation example:

<?php
Products::create()
    ->condition('user', 'Products.User = ?', 10) // 10 - User ID
    ->condition('price', 'Products.Price > ?', 5000) // Price is greater than 5000
    ->condition('stock', 'Products.Stock > ?', 0) // Quantity is greater than 0
    ->combine(['user','price', 'stock'], 'and', 'u_p_s') // combine conditions into one
    ->condition('ignore', 'Products.Ignore = ?', 1) // If 1 then show product anyway
    ->where(['u_p_s','ignore'], 'or') // Compare 2 conditions
    ->find();

18 July 18
654
0

Comments

Name
E-mail
Rating
Review

Other articles from the category

25 April 2022

Create and download CSV in PHP

Consider the possibility of quickly creating a CSV file with automatic file download. Consider the formation, separators and header for the ability to download the file.

19 June 2019

ImageCMS Templates 4.10-4.12.1

Latest templates from ImageCMS 4.12, authorization is required to download.

26 January 2019

Long-term storage of the basket in the online store

Consider options for popular options for storing goods in a shopping cart in an online store. Let's outline the pros and cons of such storage. Consider options for long-term storage of the basket.

17 January 2019

License key for ImageCMS 4.9-4.12.1 Pro and Pre

Creating a key for imageCMS 4.9-4.12.1 Pro and Pre. You must be logged in to receive it.

07 December 2018

$_SERVER[DOCUMENT_ROOT] in CLI or Cron

When running the script from the console, there is no DOCUMENT_ROOT in $_SERVER. Let's try to get around this in our own ways, catch the file directory.

31 October 2018

Analysis of loaded parts of Php code with xhprof

After developing any tool in PHP, the question becomes how resourceful the created code is and what elements it still affects. Let's take a look at xhprof installation, configuration, and how to work with xhprof.

14 June 2018

Authorization 1C on the site PHP_AUTH_USER on CentOS apache

Faced the problem of authorization 1s on the site. For some reason, the server did not accept the PHP_AUTH_USER and PHP_AUTH_PW parameters from it. Let's take a closer look at the solution and bypassing these parameters in $_SERVER .

21 May 2018

Joining an undeclared table in Propel or Join Custom Table Propel

The purpose of the article was to join (join) a table not declared in the schema (schema.xml) in propel2. Apparently a rare case or simply not enough documentation for this Propel ORM.

Categories

  • Unix OS
  • Php
  • MySQL
  • JavaScript
  • Package Managers
  • Docker
  • Seo

Latest comments

Добрый день, Сергей. Я на более новых версиях блют...
root-i
23.02.23
Пробовал на transmart колонке. Ничего из перечисле...
Сергей
20.02.23
HenryMit, может быть
root-i
07.02.23
Неофрейдизм — это… Определение, принципы, представ...
HenryMit
07.02.23

I share information in which I needed help and spent a lot of time figuring it out. If the information helped at least one person, then this site was not created in vain.

Thank you for the continuation of the site:
Contacts

Telegram Viber Mail

Search for articles

  • Sign in
  • Create Account

Powered by chmod -R