scoumbourdis/grocery-crud-databases — pull request #3 by goFrendiAsgard (2013-06-22 16:24:53+00:00)
Title: Bugfix. Relation to the same table also work in postgre

Hi, @scoumbourdis, I've make some typo bugfix.

Also, now relation to the same table also work in postgre. I check it by using navigation management (`cms_navigation` table) in No-CMS which has relation to itself. It's now fully work, except the order turn into upside down.

BTW, there is something I want to ask.
In `grocery_crud_model.php`, you have this:
```php
if(!empty($this->relation))
{
foreach($this->relation as $relation)
{
list($field_name , $related_table , $related_field_title) = $relation;
$unique_join_name = $this->_unique_join_name($field_name);
$unique_field_name = $this->_unique_field_name($field_name);

if(strstr($related_field_title,'{'))
{
$related_field_title = str_replace(" "," ",$related_field_title);
$select .= ", CONCAT('".str_replace(array('{','}'),array("',COALESCE({$unique_join_name}.",", ''),'"),str_replace("'","\\'",$related_field_title))."') as $unique_field_name";
}
else
{
$select .= ", $unique_join_name.$related_field_title AS $unique_field_name";
}

if($this->field_exists($related_field_title))
$select .= ", `{$this->table_name}`.$related_field_title AS '{$this->table_name}.$related_field_title'";
}
}
```

I'm curious in this part:
```php
if($this->field_exists($related_field_title))
$select .= ", `{$this->table_name}`.$related_field_title AS '{$this->table_name}.$related_field_title'";
```
Basically this will produce something like:
```
SELECT table_name.*, ...., table_name`.field_name AS 'table_name.field_name',..... FROM .....
```
Why do you need to do this since you already has tablename.* ?

In postgre, such a syntax is not supported.

First, I try to use `grocery_crud_generic_model` which is inherited from `grocery_crud_model` and try to omit it since I don't see any usage of it. But then, I realize that the library will assign `table_name.field_name` into the view.

Now, I end up with a bit dirty hack: `application/models/grocery_crud_generic_model.php` at line 118.
What do you think?