Welcome Guest, Not a member yet? Register   Sign In
array_column does not work with Entity
#10

(This post was last modified: 06-05-2024, 01:02 AM by warcooft.)

Try with this migration, this only happens if the primary key is not an id as in general, then create 1 dummy data and run query builder method llike model(NotificationSettingModel::class)->find([1,2]);

PHP Code:
<?php

namespace App\Database\Migrations;

use 
CodeIgniter\Database\Migration;

class 
NotificationSettings extends Migration
{
    public function up()
    {
        $this->db->disableForeignKeyChecks();
        $this->forge->addField([
            'user_id' => [
                'type'      => 'INT',
                'constraint' => 12,
                'unsigned'  => true,
                'null'      => false,
            ],
            'email_schedule' => [
                'type'      => 'tinyint',
                'constraint' => 1,
                'unsigned'  => true,
                'null'      => false,
                'default'    => 1,
            ],
            'email_surat_tugas' => [
                'type'      => 'tinyint',
                'constraint' => 1,
                'unsigned'  => true,
                'null'      => false,
                'default'    => 1,
            ],
            'created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP',
            'updated_at' => ['type' => 'DATETIME''null' => true],
        ]);
        $attributes = ['ENGINE' => 'InnoDB'];
        $this->forge->addKey('user_id'truetrue);
        $this->forge->addForeignKey('user_id''users''id'false'CASCADE');
        $this->forge->createTable('notification_settings'true$attributes);
        $this->db->enableForeignKeyChecks();
    }

    public function down()
    {
        $this->forge->dropTable('notification_settings'falsetrue);
    }


here Entities:

PHP Code:
<?php

namespace App\Entities;

use 
CodeIgniter\Entity\Entity;

class 
NotificationSetting extends Entity
{
    protected $datamap = [];
    protected $dates  = ['created_at''updated_at'];


Models:

PHP Code:
<?php

namespace App\Models;

use 
App\Entities\NotificationSetting;
use 
CodeIgniter\Model;

class 
NotificationSettingModel extends Model
{
    protected $table            'notification_settings';
    protected $primaryKey      'user_id';
    protected $useAutoIncrement false;
    protected $returnType      NotificationSetting::class;
    protected $useSoftDeletes  false;
    protected $protectFields    true;
    protected $allowedFields    = [
        'user_id''email_schedule''email_surat_tugas',
    ];
    protected bool $allowEmptyInserts false;

    protected array $casts  = [
        'user_id'          => 'integer',
        'email_schedule'    => 'int-bool',
        'email_surat_tugas' => 'int-bool',
    ];

    // Dates
    protected $useTimestamps true;
    protected $dateFormat    'datetime';
    protected $createdField  'created_at';
    protected $updatedField  'updated_at';
    protected $deletedField  'deleted_at';

    // Validation
    protected $validationRules      = [];
    protected $validationMessages  = [];
    protected $skipValidation      false;
    protected $cleanValidationRules true;

    // Callbacks
    protected $allowCallbacks true;
    protected $beforeInsert  = [];
    protected $afterInsert    = [];
    protected $beforeUpdate  = [];
    protected $afterUpdate    = [];
    protected $beforeFind    = [];
    protected $afterFind      = [];
    protected $beforeDelete  = [];
    protected $afterDelete    = [];

    /**
    * Get settings with active email thread notifications.
    */
    public function withScheduleNotification()
    {
        $this->groupStart()->where('email_schedule'1)->groupEnd();
        return $this;
    }

    /**
    * Get settings with active email thread notifications.
    */
    public function withSuratTugasNotification()
    {
        $this->where('email_surat_tugas'1);

        return $this;
    }

@xxxx[{::::::::::::::::::::::::::::::::>
Reply


Messages In This Thread
RE: array_column does not work with Entity - by warcooft - 06-05-2024, 12:22 AM



Theme © iAndrew 2016 - Forum software by © MyBB