![]() |
Request for Enhanced Validation Rules: is_unique and is_not_unique - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Feature Requests (https://forum.codeigniter.com/forumdisplay.php?fid=29) +--- Thread: Request for Enhanced Validation Rules: is_unique and is_not_unique (/showthread.php?tid=91760) |
Request for Enhanced Validation Rules: is_unique and is_not_unique - maniaba - 10-04-2024 The is_unique and is_not_unique validation rules offer robust ways to ensure data integrity when checking for the uniqueness or existence of values within a specific table. However, there's a scenario where the current implementation can be further enhanced, particularly when dealing with multiple database groups (dbGroup) in a model with foreign keys from different databases. Current Validation Rules
Proposed Enhancement: Supporting Multiple dbGroup In many real-world applications, models can involve multiple foreign keys referencing tables in different database groups. To streamline the validation process, I propose introducing support for a database group (dbGroup) prefix within the is_unique and is_not_unique rules. This would allow developers to specify the database group directly in the validation rule, improving flexibility and reducing complexity in code that handles multiple databases. Example: Consider a scenario where you have two foreign keys in a model, each pointing to different databases:
PHP Code: 'email' => 'is_unique[dbGroup1.users.email,id,123]', This implementation would ensure that the validation rule queries the correct database group, which is particularly useful when working with multiple data sources. Priority of dbGroup In this proposal, the priority of which dbGroup is used during validation would follow a clear order:
The proposed enhancement to the is_unique and is_not_unique validation rules by allowing the optional inclusion of dbGroup would greatly simplify validation for models that span multiple database groups. This enhancement aligns well with CodeIgniter's existing feature of specifying dbGroup in the run() method for validation. I believe this improvement would enhance the developer experience, reduce boilerplate code, and offer greater flexibility in managing complex database structures. Feel free to share your thoughts and any feedback on this proposal. RE: Request for Enhanced Validation Rules: is_unique and is_not_unique - Bosborne - 10-06-2024 I am sure the developers would gladly consider a PR with the proposed changes, The very small developer team is focused on maintaining & refining the current code & features. Open source projects such as this depend on other users to enhance functionality. RE: Request for Enhanced Validation Rules: is_unique and is_not_unique - ozornick - 10-06-2024 Everything is great. But you're talking about a lot of developers. Forum and repository activity are low. Will this feature be useful to everyone? To begin with, you can create your own validation function or show a PR RE: Request for Enhanced Validation Rules: is_unique and is_not_unique - maniaba - 10-06-2024 (10-06-2024, 05:30 AM)ozornick Wrote: Everything is great. But you're talking about a lot of developers. Thank you for your feedback! I've already created a PR with my suggestion: PR #9216. Feel free to take a look! |