Set_Relation breaks the search
- Single Page
Posted 10 July 2012 - 17:37 PM
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,
Posted 11 July 2012 - 06:40 AM
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
Posted 25 September 2012 - 07:10 AM
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);
}
}
}
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