Skip to content

buildKey function affecting Eloquent relationships #1469

@mentamarindos

Description

@mentamarindos

Describe the bug

I struggle for two days trying to figure out why my query with the relationships @hasOne @belongsTo wasn't working for me, and after looking into the source code I found THIS function buildKey() in the BatchLoader.php file that has the description: Build a key out of one or more given keys, supporting composite keys. which receives the parameter $key, so the problem (in my case) is that this $key variable is always NULL so I change it to:

Edited:

protected function buildKey($key): string
    {
        return true;
    }

Original:

protected function buildKey($key): string
    {
        return is_array($key) ? implode('___', $key) : $key;
    }

and Voilà, now my query works perfectly :D

The question is why?
because it's still not entirely clear to me how that actually works, could you please explain? maybe I'm doing it wrong and haven't noticed. Thank you ♥


Lighthouse Version

"require": {
        "php": "^7.2.5",
        "fideloper/proxy": "^4.2",
        "firebase/php-jwt": "^5.2",
        "fruitcake/laravel-cors": "^1.0",
        "guzzlehttp/guzzle": "^6.3",
        "laravel/framework": "^7.0",
        "laravel/tinker": "^2.0",
        "mll-lab/graphql-php-scalars": "^3.1",
        "mll-lab/laravel-graphql-playground": "^2.1",
        "nuwave/lighthouse": "^4.14"
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions