(06-17-2022, 05:09 AM)MikiStoni Wrote: Hi Devs
I used Composer to update my codeigniter to 4.21. Now I get an error message when calling getCompiledSelect. Is there another bug?
Greetings, Mike
Error Message
CodeIgniter\Exceptions\ModelException
You cannot use `getCompiledSelect()` in `App\Models\PreferencesFirmModel`. This is a method of the `Query Builder` class.
Controller
Code:
$builder = new PreferencesFirmModel();
$builder->select('id');
$builder->where('team', '0' . $show_team);
$builder->where('active', '1');
$builder->where('deleted_at', NULL);
$sql = $builder->getCompiledSelect(false);
$builder->query($sql);
Model
Code:
<?php namespace App\Models;
use CodeIgniter\Database\ConnectionInterface;
use CodeIgniter\Model;
class PreferencesFirmModel extends Model {
protected $table = 'data_company';
protected $primaryKey = 'id';
protected $returnType = 'array';
protected $useSoftDeletes = true;
// this happens first, model removes all other fields from input data
protected $allowedFields = [
'active', ..........
];
protected $useTimestamps = true;
protected $createdField = 'created_at';
protected $updatedField = 'updated_at';
protected $deletedField = 'deleted_at';
protected $validationRules = [];
protected $validationMessages = [];
protected $skipValidation = false;
// we need different rules for registration, account update, etc
protected $dynamicRules = [
'newFirma' => [
'firma' => 'required|min_length[3]|max_length[100]',
.........
],
'updateFirm' => [
'firma' => 'required|min_length[3]|max_length[100]',
..........
],
'updateSort_ci' => [
'sortable_ci' => 'required',
],
'updateSort_ii' => [
'sortable_ii' => 'required',
],
'delSort' => [
'id' => 'required',
]
];
//--------------------------------------------------------------------
/**
* Changes validation rules dynamically
*/
public function setValidationRules($rules) {
$this->validationRules = $this->dynamicRules[$rules];
}
}
try this:
$PreferencesFirmBuilder = new PreferencesFirmModel();
$sql =$PreferencesFirmBuilder->select('id')->where('team', '0' . $show_team)->where('active', '1')->where('deleted_at', NULL)->
builder->getCompiledSelect(false);