Add index_by() method to Query Builder |
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)
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 (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!
When you fetch data by database then you can use result(); and after that you can combine two array using array_combine() function.
|
Welcome Guest, Not a member yet? Register Sign In |