Welcome Guest, Not a member yet? Register   Sign In
Insert in database return false without error
#3

(03-23-2020, 09:42 AM)MGatner Wrote: Could you drop the catch block and figure out exactly where the FALSE is coming from? If it is indeed from the model try checking $accountModel->errors() for anything helpful. You might also review your log settings while you're in there. https://codeigniter4.github.io/userguide...gging.html

Log is setted right.

I removed try-catch and same result and $accountModel->errors() is null.

After some research, I found that in `$accountModel->insert(...)`call `classToArray`.
That `classToArray` check `if(method_exists($data, 'toRawArray'))`, which will call that method to get my object as an raw array.
Super class of `Account` is `Entity`(why? I don't know, I just did copy-paste). `Entity` has `toRawArray`, to `toRawArray` return an empty raw array(no attributes). The way is to override `toRawArray` in `Account`, but I have no reason to keep `extends Entity`.
I removed `extends Entity`, but that still didn't solved the problem.
Attributes of `Account` are private, and the `classToArray` collect only public and protected attributes, so I made attributes protected and now everything works fine.
Reply


Messages In This Thread
RE: Insert in database return false without error - by raul1ro - 03-23-2020, 12:23 PM



Theme © iAndrew 2016 - Forum software by © MyBB