Using Model's CRUD methods in advanced queries |
Hi all,
I have created 3 tables in my database. Code: Products (ID, name) 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.
https://codeigniter4.github.io/CodeIgnit...ilder.html
Hi RobT,
What you're asking for is more about ORM than CRUD. CI4 comes with some basic CRUD / ORM tools (see https://codeigniter4.github.io/userguide...model.html) 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: https://www.concorde-project.org Have a good day, Vincent
I have a module to add some basic relationship loading to CodeIgniter 4. Please read through the docs before use. https://github.com/tattersoftware/codeig...-relations
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(); var_dump($products->categories); |
Welcome Guest, Not a member yet? Register Sign In |