contao/import — Issue #2485: Doctrine/Propel like functions
Author: importer
Created: 2011-11-29 19:39:07+00:00
State: open
Labels: Accepted, Feature, framework

I would like to request Doctrine/Propel like functions where() and orderBy(). So far there exists only one such function limit().

Let's imagine you have one module to list database records. Each record has its parent (e.g. category). Everything goes fine until you want to list ALL of items. At the moment you can achieve this by using the code

```
$intCategory = (int) $this->Input->get('cat');
if ($intCategory)
{
$strQuery = ' WHERE pid=' . $intCategory;
}
$objQuery = $this->Database->execute("SELECT * FROM tl_items".$strQuery);
```

However, if we've got functions like where():

```
$intCategory = (int) $this->Input->get('cat');
$objQuery = $this->Database->prepare("SELECT * FROM tl_items");

if ($intCategory)
{
$objQuery->where('cat', $intCategory);
}

$objStmt->execute();

// or even
$objQuery = $this->Database->prepare("SELECT * FROM tl_items")->where('cat', $intCategory')->execute();
```

The similar thing happens to the orderBy() function.

I know you can select the categories you would like to display in module edit view, but sometimes it's just more work that it's worth:

```
$objQuery = $this->Database->execute("SELECT * FROM tl_items WHERE pid IN(" . implode(',', array_map('intval', $this->categories)) . ")");
```

--- _Originally created by qzminski on August 28th, 2010, at 09:12pm (ID 2485)_