CodeIgniter Forums
UUID bug with Entity - 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: UUID bug with Entity (/showthread.php?tid=87782)



UUID bug with Entity - FabriceL - 05-31-2023

Hi, there,

I'm making a seed with this example below:

Code:
$formatters = [
            'raison_social' => 'sentence',
            'nom' => 'sentence',
            'prenom' => 'sentence',
            'email'  => 'email',
        ];

        $fabricator = new Fabricator(CustomerModel::class, $formatters);

        for ($i = 0; $i < 5; $i++) {
            $data[] = $fabricator->make();
            $data[$i]->uuid = newUUID();
            $data[$i]->code_client = 'xfgsdfgfdsgsdfg';
            $data[$i]->id_country = 8;
            $data[$i]->type = 1;
            $data[$i]->reference = "fsgdsfgfdg";
            $data[$i]->corp_rateCategory = 1;
            $data[$i]->active = 1;
            $data[$i]->order = $i + 1;
        }

        print_r($data);

        $this->db->table('customers')->insertBatch($data);


But if I leave in my Model : 
PHP Code:
protected $returnType      Customer::class; 

This does not work, i.e. the database is populated but without the right information.

If I replace it with
PHP Code:
$returnType      "Object"


it works perfectly.
In my entity I have nothing.
Do you have an idea?

Thanks


RE: UUID bug with Entity - InsiteFX - 05-31-2023

Did you try it with passing it the namespace?

PHP Code:
protected $returnType    = \App\Entities\User::class; 



RE: UUID bug with Entity - kenjis - 06-01-2023

What happened when using Entity?


RE: UUID bug with Entity - FabriceL - 06-01-2023

(06-01-2023, 04:10 AM)kenjis Wrote: What happened when using Entity?
This code works : 
Code:
      $faker = Factory::create('id_ID');

        $data = [];
        for ($i = 0; $i < 5; $i++) {

            $data[] = [
                'uuid'    => newUUID(),
                'code_client'    => $faker->sha1,
                'id_country'        => 8,
                'raison_social' => $faker->userName,
                'nom' => $faker->lastName,
                'prenom' => $faker->firstName,
                'email' => $faker->email,
                'corp_rateCategory'    => 1,
                'active'=> 1,
                'order' => $i + 1,
                'created_at'=> $faker->dateTimeBetween('-2 month', '-1 days')->format('Y-m-d H:i:s'),

            ];

        }

on the other hand, the other code doesn't work and it doesn't return any errors. it inserts all 5 rows, but some columns are empty, like "UUID".

I don't understand


RE: UUID bug with Entity - kenjis - 06-01-2023

Does newUUID() return correct UUID?
Dump the $data value to check.
And check the executed SQL statements.