Skip to content

Conversation

@amermchaudhary
Copy link
Contributor

Q A
Branch? main for features / current stable version branch for bug fixes
Tickets Closes #6736
License MIT
Doc PR

Fixes the issue on collection relations other than HasMany not working for Laravel

@amermchaudhary amermchaudhary changed the title Patch #6736 fix(#6736) Fixes the issue on collection relations other than HasMany not working for Laravel Oct 20, 2024
@soyuka
Copy link
Member

soyuka commented Oct 21, 2024

nice thanks! Isn't there an interface that all these HasMany classes implement to avoid listing them?

@amermchaudhary
Copy link
Contributor Author

amermchaudhary commented Oct 21, 2024

nice thanks! Isn't there an interface that all these HasMany classes implement to avoid listing them?

sadly, no. All relation classes extend Relation class but nothing specific for HasMany classes

@soyuka soyuka changed the title fix(#6736) Fixes the issue on collection relations other than HasMany not working for Laravel fix(laravel): collection relations other than HasMany Oct 23, 2024
@soyuka soyuka merged commit ac6f667 into api-platform:4.0 Oct 23, 2024
58 of 59 checks passed
@soyuka
Copy link
Member

soyuka commented Oct 23, 2024

awesome! thanks @amermchaudhary

@Jehong-Ahn
Copy link

I'm new to API Platform and I'm still having trouble integrating belongsToMany relationships. Could you provide an example, or perhaps enhance the examples in /src/Laravel/workbench/app/Models?

@amermchaudhary
Copy link
Contributor Author

@Jehong-Ahn the issue is fixed in version 4.0.6. Please make sure you have the latest code

@amermchaudhary
Copy link
Contributor Author

amermchaudhary commented Oct 28, 2024

Example:

    public function projects() : HasManyThrough {
        return $this->hasManyThrough(Project::class, ProjectUser::class, 'user_id', 'id', 'id', 'project_id');
    }    

@Jehong-Ahn
Copy link

Thanks @amermchaudhary! I see we can use HasManyThrough.

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

Successfully merging this pull request may close these issues.

4 participants