Add index_by() method to Query Builder - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6) +--- Forum: CodeIgniter 3.x (https://forum.codeigniter.com/forumdisplay.php?fid=17) +--- Thread: Add index_by() method to Query Builder (/showthread.php?tid=69820) |
Add index_by() method to Query Builder - Elias - 01-21-2018 Hello! How about adding index_by() method to DB Query Builder or DB result (maybe in 3.2 release)? It will be helpful functionality and does not break the old code. Example of implementation: PHP Code: public function index_by($field_name) Example of using: PHP Code: $this->db->get('elements')->index_by('slug')->result_array(); Result data: Code: Array I do not have enough knowledge about CodeIgniter code-base for try to add this method by pull-request on GitHub. And I want to know opinion of CI developers and community about this. That's why I'm here) RE: Add index_by() method to Query Builder - Narf - 01-21-2018 Has been suggested before. I don't like it, can break if the column doesn't have a constraint. And it's not like it's hard to do ... Code: // $result is whatever result_array() gave you RE: Add index_by() method to Query Builder - Elias - 01-22-2018 (01-21-2018, 11:36 PM)Narf Wrote: Has been suggested before. I don't like it, can break if the column doesn't have a constraint. Yes, I know, it is not difficult to do. But if it will be a part of Query Builder it will be cleaner and more beautiful. Anyway, it is not critical feature. Thanks for reply! RE: Add index_by() method to Query Builder - XtreemDeveloper - 01-22-2018 When you fetch data by database then you can use result(); and after that you can combine two array using array_combine() function. |