Using Model's CRUD methods in advanced queries - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30) +--- Thread: Using Model's CRUD methods in advanced queries (/showthread.php?tid=74732) |
Using Model's CRUD methods in advanced queries - RobT - 10-30-2019 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. RE: Using Model's CRUD methods in advanced queries - edica - 10-30-2019 Yes. You can also use other Query Builder Class functions. https://codeigniter4.github.io/CodeIgniter4/database/query_builder.html RE: Using Model's CRUD methods in advanced queries - vincent78 - 10-30-2019 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/models/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 RE: Using Model's CRUD methods in advanced queries - RobT - 10-30-2019 Thanks for your reply, @edica and @vincent78. RE: Using Model's CRUD methods in advanced queries - MGatner - 11-01-2019 I have a module to add some basic relationship loading to CodeIgniter 4. Please read through the docs before use. https://github.com/tattersoftware/codeigniter4-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); RE: Using Model's CRUD methods in advanced queries - RobT - 11-04-2019 Thank you, @MGatner. |