yajra / laravel-oci8

Oracle DB driver for Laravel via OCI8

Home Page:https://yajrabox.com/docs/laravel-oci8

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ORA-00918: column ambiguously defined with orderBy()

nmalcolm opened this issue · comments

commented

Summary of problem or feature request

I'm getting a column ambiguously defined error while using standard Eloquent methods (and a pivot table) which work on Postgres and MySQL.

Code snippet of problem

Controller:

$foos = auth()->user()->foos()->orderBy('created_at', 'desc')->get();

User.php

    public function foos()
    {
        return $this->belongsToMany('App\Models\Foo')->withPivot('note')->withTimestamps();
    }

Failing query:

select "FOOS".*, "FOO_USER"."USER_ID" as "PIVOT_USER_ID", "FOO_USER"."FOO_ID" as "PIVOT_FOO_ID", "FOO_USER"."NOTE" as "PIVOT_NOTE", "FOO_USER"."CREATED_AT" as "PIVOT_CREATED_AT", "FOO_USER"."UPDATED_AT" as "PIVOT_UPDATED_AT" from "FOOS" inner join "FOO_USER" on "FOOS"."ID" = "FOO_USER"."FOO_ID" where "FOO_USER"."USER_ID" = :p0 order by "CREATED_AT" desc

Replacing orderBy('created_at', 'desc') with orderBy('foos.created_at', 'desc') doesn't work as foos. is removed from the query.

As a workaround, we can order the data using PHP instead:

$foos = auth()->user()->foos()->get()->sortByDesc('created_at');

System details

  • Ubuntu 22.04
  • PHP 8.1
  • Laravel 9
  • Laravel-OCI8 9.3.1
commented

This has been previously mentioned:

#298 (comment)

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

This issue was closed because it has been inactive for 7 days since being marked as stale.