Skip to content

can't use the same model to update, delete and insert record #1193

Description

@emiglobetrotting

I am using CodeIgniter model with an Entity class; but it seems i cannot use the same model to do insert, save, delete, and update records.

This left me created UpdatingModel and SaveInsertModel but all using the same Entity Class.

DriverModel.php use this for save and insert

<?php namespace App\Models;

class DriverModel extends \CodeIgniter\Model
{
  protected $table      = 'drivers';

  //protected $primaryKey = 'driverid';

  protected $dbGroup = 'default';

  protected $returnType = '\App\Entities\Drivers';

  protected $useSoftDeletes = false;

  protected $allowedFields = [
	'driverid',
	'truckcapacity'
  ];

  protected $useTimestamps = false;

  protected $validationRules = [];

  protected $validationMessages = [];

  protected $skipValidation     = false;
}

DriverUpdatingModel.php use this do update and delete records from drivers table

<?php namespace App\Models;

class DriverUpdatingModel extends \CodeIgniter\Model
{
  protected $table      = 'drivers';

  protected $primaryKey = 'driverid';

  protected $dbGroup = 'default';

  protected $returnType = '\App\Entities\Drivers';

  protected $useSoftDeletes = false;

  protected $allowedFields = [
	'driverid',
	'truckcapacity'
  ];

  protected $useTimestamps = false;

  protected $validationRules = [];

  protected $validationMessages = [];

  protected $skipValidation     = false;
}

The Entity Class is this :

Drivers.php

<?php namespace App\Entities;

use CodeIgniter\Entity;

class Drivers extends Entity
{
protected $driverid;
protected $truckcapacity;
}

doing this will not work

$drivermodel = new \App\Models\DriverModel();
$field = ['truckcapacity'=>500];
$drivermodel->update($driverid,$field); 

this will work

$drivermodel = new \App\Models\DriverUpdatingModel();
$field = ['truckcapacity'=>500];
$drivermodel->update($driverid,$field); 

I don't know if this is a bug or how it should be used or something is wrong with my Model class data attributes and allowed fields.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions