-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: Error in Seeder #2653
Comments
Can you please provide an example of what you are passing to the validation? E.g. what your Seed is actually trying to insert? |
I was trying to reproduce this error but with no luck. I could get this error only when I was using an array as an input value. |
Thanks for taking a look at this. I tried to replicate this in my end but I figured out that I had it wrong by using fzaninotto/faker. I used However, the second issue I stumbled upon is the
|
The rule for The thing is there will be no valuation errors displayed by default. You have to write some code to handle this, so something like this should help (after insert): if ($errors = $yourModel->errors())
{
foreach ($errors as $error)
{
\CodeIgniter\CLI\CLI::write($error, 'red');
}
} My guess is that this is something related to your database structure? You don't have |
Thanks! |
I had a similar Error just now, i think it has a Problem if you have a field in your Validation Rule that you don't want to insert and also isn't in your allowedFields. The behavior was different in the RC Version, there it worked fine to use Validation rules in a model that include fields that are not inserted into the DB. |
@JoelCatantan things like data validation in seeders are up to you. From my perspective validating data in the seeder is not a very common thing since we usually know well what we're inserting. But I get it - for you, it's not the case... that's why data validation is not included by default. @Tysonpower are you saying you get an error or you experienced an unexpected behavior? Could you by any chance provide some code sample that allows us to recreate this issue? |
@michalsn Here is a short Code snippet, it is unexcepted/Different Behaviour then on the RC. The Problem is the passwordrepeat Field, i need to check it to validate the Form but i don't insert it into the DB Of course. The RC Just ignored the passwordrepeat while saving because it isn't in the Entity and also not in the Allowed Fields list. Controller
userModel
|
Well... if |
I just tested it with my code above again (entity has no passwordrepeat field btw.) and the model->errors() show the following: [passwordrepeat] => The passwordrepeat field is required. So your Solution is just adding the passwordrepeat Field to the Entity that is given to the model->save() right? I don't really like that but well, if that is the new Behaviour instead of the one in the RC than i'm okay with that and just store the Validation Rules for the Form in the Controller. |
@Tysonpower you know what? Can I ask you to start a thread on the forum with a minimum amount of code that will make it possible to recreate this issue? I still can't reproduce it but maybe I am missing something here... I don't want to spam everyone with our conversation since the originally reported issue is (I believe) already resolved. |
Jup, no Problem. Will make a post when i got some time on hand |
Post is currently waiting for approval, but here is the link already: https://forum.codeigniter.com/thread-75709.html |
Judging from this thread and the forum post the issues here are resolved. @Tysonpower if you agree please close. |
I didn't create the ussue here, som i can't close it. But yeah it can be closed in my opinion. |
Direction
Record did not save upon seeding when there is validationRules property in model
Describe the bug
When seeding, the value became an array instead of string/null.
CodeIgniter 4 version
CI 4.0.2, Develop Branch
Affected module(s)
system\CodeIgniter\Validation\Validation::processRules
Expected behavior, and steps to reproduce if appropriate
Put a validationRules in model then create a seeder and run. I have in_list rule in my validation and the I got an Exception:
Type: TypeError Message: Argument 1 passed to CodeIgniter\Validation\Rules::in_list() must be of the type string or null, array given, called in ...\system\Validation\Validation.php on line 279 Filename: ...\system\Validation\Rules.php Line Number: 191
However, when I remove the in_list rule, no error occurs and yet, no record had been saved
Context
The text was updated successfully, but these errors were encountered: