Many-to-many column mappings

I have very simple relation, user has many organizations and organization has many users (nothing unusual). But when I want to fetch:


Column 'organization_id' doesn't belong to the model or alias 'App\Model\UserHasOrganization', when executing: SELECT [App\Model\Organization].* FROM [App\Model\Organization] INNER JOIN [App\Model\UserHasOrganization] ON [App\Model\UserHasOrganization].[organization_id] = [App\Model\Organization].[id] WHERE [App\Model\UserHasOrganization].[user_id] = :APR0:

I recognize that when I replace columns mapping, it works:

    public function columnMap()
        return [
            'organizationId' => 'organization_id'

But now second side is spoiled:


Is a simple way to recognize a relation side and use array_flip to set columnMap dynamic?

If you have n:n relations, then you have to access them as arrays:

foreach($result->organization as $organization) {
    foreach($organization->users as $user) {