![]() |
Roster: Relation Name Lookup - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Addins (https://forum.codeigniter.com/forumdisplay.php?fid=34) +--- Thread: Roster: Relation Name Lookup (/showthread.php?tid=80207) |
Roster: Relation Name Lookup - MGatner - 09-28-2021 Hi all- I have some "dynamite" for you: small package, big impact! "Roster" solves a common, niche problem in an elegant way: quick access to display names for entity relations without requiring database lookup. Tatter\Roster Bulk name lookup for database relations in CodeIgniter 4 Packagist: https://packagist.org/packages/tatter/roster GitHub: https://github.com/tattersoftware/codeigniter4-roster An example to demonstrate how it works... You are developing a blog. At the bottom of every post is a comments section where logged in users may post replies. In order to display the user names next to each comment you need to cross-reference your "comments" table with the "users" table. You can:
Here's what your Roster looks like for Users, in app/Rosters/UserRoster.php: PHP Code: namespace App\Rosters; The Roster Service handles locating your Roster and matching the ID, so you can use it inline right in your HTML: Code: <?php foreach ($comments as $comment): ?> That's all! As always check out the docs, give it a try, and send over any feedback you have. RE: Roster: Relation Name Lookup - InsiteFX - 09-29-2021 Thanks, will check it out later. RE: Roster: Relation Name Lookup - paliz - 09-30-2021 Thank you its great feature RE: Roster: Relation Name Lookup - includebeer - 10-05-2021 This looks interesting and useful, but isn't it a little bit over engineered just to cache a key/value? RE: Roster: Relation Name Lookup - MGatner - 10-07-2021 > isn't it a little bit over engineered I suppose some may feel so. I tend to use libraries like project-level traits: reusable components to prevent duplicating code. In this case the concept was developed on a project using Firestore (NoSQL) where joins are not possible so looking up a single field for related items can be very costly. The flip side is that bulk reads of subcollections are cheap, so being able to load and cache the field all at once is a huge performance gain. For sure there are other ways to handle this, but I think regardless of your backend database this will be the most efficient for 95% of the scenarios that match the description. RE: Roster: Relation Name Lookup - includebeer - 10-07-2021 Oh, don't get me wrong. I totally agree on the final result (reusable component + performance gain). I was just surprised by the amount of code for something that in my opinion is relatively simple. But maybe if I was to develop something similar I would end up with the same amount of code. |