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

SQL Syntax Error with CanBeOneOfMany if primaryKey of related model is null #46463

Closed
smecnarowski opened this issue Mar 14, 2023 · 4 comments
Closed

Comments

@smecnarowski
Copy link

smecnarowski commented Mar 14, 2023

  • Laravel Version: 8.3.4 (Lumen)
  • PHP Version: 8.0
  • Database Driver & Version:

Description:

SQL parsers adds empty column to query. Problems exists in core Laravel till today as I see in repo.

Steps To Reproduce:

Add relation to your model

public function test()
{
    return $this->hasOne(Relation::class)->ofMany('sorted_column');
}

Relation have to be with nulled primaryKey

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Relation extends Model
{
    protected $primaryKey = null;

    public $incrementing = false;

    public $timestamps = false;
}

Problems starts when $keyName became null in here https://github.com/laravel/framework/blob/10.x/src/Illuminate/Database/Eloquent/Relations/Concerns/CanBeOneOfMany.php#L77

Possible solution is to ignore null here https://github.com/laravel/framework/blob/10.x/src/Illuminate/Database/Eloquent/Relations/Concerns/CanBeOneOfMany.php#L93

if (!$column) {
    continue;
}
@driesvints
Copy link
Member

Hey there,

Unfortunately we don't support this version anymore. Please check out our support policy on which versions we are currently supporting. Can you please try to upgrade to the latest version and see if your problem persists? If so, please open up a new issue and we'll help you out.

Thanks!

@driesvints
Copy link
Member

Please also don't open Lumen issues on the framework repo.

@smecnarowski
Copy link
Author

@driesvints I mentioned in first paragraph "Problems exists in core Laravel till today as I see in repo." So with almost 100% sure it exists in 10.x also.

@smecnarowski
Copy link
Author

@driesvints are you going to recheck it for 10.x ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants