yajra / laravel-oci8

Oracle DB driver for Laravel via OCI8
https://yajrabox.com/docs/laravel-oci8
MIT License
833 stars 237 forks source link

Problem with ORM update #877

Closed Kh4os-afk closed 1 month ago

Kh4os-afk commented 2 months ago

Summary of problem or feature request

Hey! my oracle database has several composite primary keys, which forced me to set the $primaryKey of the Models to 'rowid', when I am using the Find method with rowid in string the line in question is returned without problems, however when trying to apply a update in this variable and checking the logs I notice that Laravel tried to apply an update to null

Code snippet of problem

Model:

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class PCPrest extends Model
{
    protected $connection = 'oracle';
    protected $table = 'pcprest';
    protected $keyType = 'string';  
    protected $primaryKey = 'rowid';
    public $timestamps = false;
    protected $fillable = ['obs'];

    public function cobranca()
    {
        return $this->hasOne(PCCob::class,'codcob','codcob');
    }
}

Render Method (Livewire Controler)


public function render()
    {
        $prest = PCPrest::where('rowid','AAAYBKAEZAAAA1DAAA')->first();

        $prest->update(['obs' => 'teste laravel']);  //Error <-- update "PCPREST" set "OBS" = 'teste laravel' where "ROWID" is null

        return view('livewire.desdobrar', [
            'prestacoes' => BDCPrest::with('bdccartoes')->paginate(25),
        ]);
    }

System details

Laravel DebugBar

Connection Established
Desdobrar.php#52
select * from (select * from "PCPREST" where "ROWID" = 'AAAYBKAEZAAAA1DAAA') where rownum = 1
83.09ms

OracleBuilder.php#159
update "PCPREST" set "OBS" = 'teste laravel' where "ROWID" is null
660μs

Desdobrar.php#54
select count(*) as aggregate from `bdc_prest`
2.06ms
conciliador

error

ErDiabIo commented 2 months ago

Hi @Kh4os-afk,

Eloquent doesn’t support composite primary keys, see link belowe, https://laravel.com/docs/11.x/eloquent#composite-primary-keys

but you can try to use https://github.com/thiagoprz/eloquent-composite-key

github-actions[bot] commented 1 month ago

This issue is stale because it has been open for 30 days with no activity.