CodeIgniter Forums
find() should be renamed - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forum-28.html)
+--- Forum: CodeIgniter 4 Feature Requests (https://forum.codeigniter.com/forum-29.html)
+--- Thread: find() should be renamed (/thread-77240.html)



find() should be renamed - demyr - 08-05-2020

Hi there,

That might sound funny but the find() function creates a misunderstanding for me when I, the coder of my own project, read the code later.

For example, when I read this after a while :

PHP Code:
$m = new GalleryModel();
$data['category_of_the_gallery'] = $m->find($gallery_category_id); 

I understand that I am trying to find "gallery_category_id".

Actually, not.

I believe the find() should be renamed as find_row_with();  - or - find_row_by_using();
If you want to specify more than one row to return by passing an array of primaryKey values instead of just one, that should be:
find_rows_with();

I believe everything would be more readable :

find_the_row_by_using($gallery_category_id)  or just  find_with([b]$gallery_category_id) [/b]is fine

You see? Smile


RE: find() should be renamed - natanfelles - 08-05-2020

Normally, I call model functions name with By. For example: findBySlug(string $slug): Post


RE: find() should be renamed - MGatner - 08-06-2020

This won’t happen. But you could do it yourself - add ‘find_row_by_id’ to BaseModel.php and have it call find(), then you can use your own function. I personally like the terse nature of “find”


RE: find() should be renamed - demyr - 08-12-2020

(08-06-2020, 04:39 AM)MGatner Wrote: This won’t happen.  But you could do it yourself - add ‘find_row_by_id’ to BaseModel.php and have it call find(), then you can use your own function. I personally like the terse nature of “find”

at least a find_with would be fine Smile