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

Problem with ORM update #877

Closed
Kh4os-afk opened this issue Aug 7, 2024 · 2 comments
Closed

Problem with ORM update #877

Kh4os-afk opened this issue Aug 7, 2024 · 2 comments
Labels

Comments

@Kh4os-afk
Copy link

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

  • Operating System: Windows 11
  • PHP Version: 8.2.17
  • Laravel Version: 10.48.14
  • Laravel-OCI8 Version: 10.6.0

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
Copy link
Contributor

ErDiabIo commented Aug 7, 2024

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

Copy link

github-actions bot commented Sep 7, 2024

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

@github-actions github-actions bot added the stale label Sep 7, 2024
@yajra yajra closed this as completed Sep 7, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Sep 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants