CodeIgniter Forums

Full Version: Using Model's CRUD methods in advanced queries
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi all,
I have created 3 tables in my database.

Products (ID, name)
Categories (ID, name)
Products_Categories (productID, categoryID)

This last table is used to link one or more categories to one or more products.
Can I use CRUD methods available in CI 4 to get, for example, all products in a given category?
Thanks for your help.
Yes. You can also use other Query Builder Class functions.
Hi RobT,

What you're asking for is more about ORM than CRUD.
CI4 comes with some basic CRUD / ORM tools (see

But many-to-many relationships are more complex than it seems, especially if there more than 2 entities implied in the association or if there are some additional attributes in the association.

I've made a try with CI3 in order to manage these kind of associations (plus the possibility to link to a concrete or abstract Model)
You can find it here:

Have a good day,
Thanks for your reply, @edica and @vincent78.
I have a module to add some basic relationship loading to CodeIgniter 4. Please read through the docs before use.

Quick start

1. Install with Composer: > composer require tatter/relations

2. Extend the model: class ProductModel extends \Tatter\Relations\Model

3. Load relations:
$products = $productModel->with('categories')->findAll();
Thank you, @MGatner.