⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Set_Relation breaks the search



thatdiegokid
  • profile picture
  • Member

Posted 10 July 2012 - 17:37 PM

I have a couple tables set but when I do a search with the built-in search function, I end up with errors (most likely because of duplicate column names).
The sql being generated looks like this
"SELECT * FROM (`listings`) LEFT JOIN `user` as je8701ad4 ON `je8701ad4`.`id` = `listings`.`user_id` WHERE `country_code` LIKE '%CA%'"

though I need it to produce something like this
"SELECT * FROM (`listings`) LEFT JOIN `user` as je8701ad4 ON `je8701ad4`.`id` = `listings`.`user_id` WHERE `listings`.`country_code` LIKE '%CA%'"

I think I need to place a table_name in the where() or or_like() call, but I'm not entirely sure what lines and functions are related to the search.

Any help would be appreciated.
Cheers,

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 11 July 2012 - 06:40 AM

Hello [member='thatdiegokid'] ,

Yes I can confirm that this is a bug as for version 1.2.3. I am preparing a new big release 1.3 and I will probably redesign all the set_relation queries. Until then I will probably have a work around for this. At least don't have this kind of errors. I will inform you for any news.

Thank you for reporting this.

Kindest Regards

Johnny

ahe
  • profile picture
  • Member

Posted 25 September 2012 - 07:10 AM

A - very - ugly hack for this problem until it can be fixed correctly. I tried to fix it it better at the generation of the list, but there seems to be some restructuring needed to get this to work right.

Edit - i just noticed this hack does not work in all situation.


diff --git a/application/libraries/grocery_crud.php b/application/libraries/grocery_crud.php
index 91b225b..33931b2 100755
--- a/application/libraries/grocery_crud.php
+++ b/application/libraries/grocery_crud.php
@@ -535,6 +535,8 @@ class grocery_CRUD_Model_Driver extends grocery_CRUD_Field_Types

if(!empty($state_info->search))
{
+ $table=$this->get_table();
+
if(!empty($this->relation))
foreach($this->relation as $relation_name => $relation_values)
$temp_relation[$this->_unique_field_name($relation_name)] = $this->_g
@@ -556,7 +558,12 @@ class grocery_CRUD_Model_Driver extends grocery_CRUD_Field_Types
}
else
{
- $this->like($state_info->search->field , $state_info->search->text);
+
+ $searchfield = $state_info->search->field;
+ if (strpos($searchfield,".")===false)
+ $searchfield=$table.'.'.$searchfield;
+
+ $this->like($searchfield , $state_info->search->text);
}
}
else
@@ -591,7 +598,12 @@ class grocery_CRUD_Model_Driver extends grocery_CRUD_Field_Types
}
else
{
- $this->or_like($column->field_name, $search_text);
+
+ $searchfield = $column->field_name;
+ if (strpos($searchfield,".")===false)
+ $searchfield=$table.'.'.$searchfield;
+
+ $this->or_like($searchfield, $search_text);
}
}
}

michaelh613
  • profile picture
  • Member

Posted 10 August 2015 - 11:12 AM

Hello [member='thatdiegokid'] ,

Yes I can confirm that this is a bug as for version 1.2.3. I am preparing a new big release 1.3 and I will probably redesign all the set_relation queries. Until then I will probably have a work around for this. At least don't have this kind of errors. I will inform you for any news.

Thank you for reporting this.

Kindest Regards

Johnny

Wondering if there is any progress on this as I am having the same problem.   Are there any known workarounds