Skip to content

one-of-many relationship is not working if primary key is UUID (i.e Not Sortable). #37854

Closed
@pushpak1300

Description

@pushpak1300
  • Laravel Version: 8.48.2
  • PHP Version: 8.0.7
  • Database Driver & Version: Postgres

Description:

It seems that the new One of Many relationships from #37362 does not work well when the primary key is UUID (i.e not sortable)

Steps To Reproduce:

public function latestSubmission()
    {
        return $this->hasOne(Submission::class)->ofMany('created_at', 'max');
    }

When UUID is used for primary keys, fetching this relationship on the model I'm getting the following error.

Illuminate\Database\QueryException with message 'SQLSTATE[42883]: Undefined function: 7 ERROR:  function max(uuid) does not exist
LINE 1: select * from "submissions" inner join (select MAX(id) as id...
                                                       ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts. (SQL: select * from "submissions" inner join (select MAX(id) as id, "submissions"."assignment_id" from "submissions" inner join (select MAX(created_at) as created_at, "submissions"."assignment_id" from "submissions" where "submissions"."assignment_id" in (919ad545-44cfd2-bfd7-598c44761d) and "submissions"."deleted_at" is null group by "submissions"."assignment_id") as "latestSubmission" on "latestSubmission"."created_at" = "submissions"."created_at" and "latestSubmission"."assignment_id" = "submissions"."assignment_id" where "submissions"."deleted_at" is null group by "submissions"."assignment_id") as "latestSubmission" on "latestSubmission"."id" = "submissions"."id" and "latestSubmission"."assignment_id" = "submissions"."assignment_id" where "submissions"."deleted_at" is null)'

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions