最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - SQL Unknown column error with first() and findAll() - Stack Overflow

programmeradmin3浏览0评论

I'm using CodeIgniter 4 and having an issue with my model. I'm using first() and findAll() to retrieve data as objects or arrays, but for some functions, I get this error:

Unknown column 'adresses_facturation.suppression' in 'where clause'

In my database, I have a column named suppression of type DATETIME.

public function getAdresse(int $idAdresse): ?object
{
    return $this->where(['idFacturation' => $idAdresse, 'suppression' => null])->first();
}

my model :

class AdressesFacturationModel extends Model
{
    protected $DBGroup = 'default';
    protected $table = 'adresses_facturation'; //Nom de la table
    protected $primaryKey = 'idFacturation'; //Clé primaire de la table
    protected $useAutoIncrement = true;
    protected $returnType = 'object'; // ou array ou object
    protected $useSoftDeletes = true;
    protected $allowedFields = [
        'idFacturation',
        'civilite',
        'nom',
        'prenom',
        'entreprise',
        'adresse',
        'complement',
        'postal',
        'ville',
        'telephone',
        'email',
        'idPays',
        'defaut',
        'utilisateurs_idUtilisateur'
    ];
    protected $useTimestamps = true;
    protected $createdField = 'creation';
    protected $updatedField = 'modification';
    protected $deletedField = 'suppression';
    protected $validationRules = [];
    protected $validationMessages = [];
    protected $skipValidation = false;
    protected $dateFormat = 'datetime';

For now I have done as code :

    public function getAdresse(int $idAdresse): ?object
    {
        return $this->where(['idFacturation' => $idAdresse, 'suppression' => null])->get()->getRow();
    }

but I would like to understand why I have the error with the first

发布评论

评论列表(0)

  1. 暂无评论