Skip to content
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

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

Closed
emiglobetrotting opened this issue Aug 31, 2018 · 1 comment
Closed

Comments

@emiglobetrotting
Copy link

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.

@lonnieezell
Copy link
Member

I haven't seen this happen, personally. And I don't see anything different between the models so what you're describing can't be a bug, as far as I can tell. Please raise the issue on the forums, and we'll see if someone can help you there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants