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

Include the reference model name in the build query when getting rela… #16655

Merged
merged 4 commits into from
Oct 21, 2024

Conversation

alrieckert
Copy link
Contributor

@alrieckert alrieckert commented Oct 1, 2024

…ted records

When we overload the getRelated function and join more tables, it can happen that the referencedField/s can't be mapped back correctly to the referenceModel it not specified

Hello!

  • Type: bug fix | new feature | code quality | documentation
  • Link to issue:

In raising this pull request, I confirm the following:

  • I have read and understood the Contributing Guidelines
  • I have checked that another pull request for this purpose does not exist
  • I wrote some tests for this PR
  • I have updated the relevant CHANGELOG
  • I have created a PR for the documentation about this change

Small description of change:

Thanks

…ted records

When we overload the getRelated function and join more tables, it can happen that the referencedField/s can't be mapped back correctly to the referenceModel it not specified
@alrieckert
Copy link
Contributor Author

alrieckert commented Oct 1, 2024

Before the fix

The column 'id' is ambiguous, when preparing:

SELECT [App\\Models\\Device\\Device].* 
FROM [App\\Models\\Device\\Device] 
JOIN [App\\Models\\User\\User] 
WHERE (([id] = :APR0:) 
    AND (App\\Models\\Role\\EntityToUser.type_id = 10)) 
    AND ([App\\Models\\User\\User].id = :user_id:)"}}

after this patch request

SELECT [App\Models\Device\Device].* 
FROM [App\Models\Device\Device] 
JOIN [App\Models\User\User] 
WHERE (([App\Models\Device\Device].[id] = :APR0:) 
    AND (App\Models\Role\EntityToUser.type_id = 10)) 
    AND ([App\Models\User\User].id = :user_id:)

Now SQL is correctly formatted

Array
(
    [sql] => SELECT 'device'.'device_id', 'device'.'device_serial' 
             FROM 'device'  
             INNER JOIN 'm2m_app'.'entity_to_user' ON 'device'.'device_id' = 'entity_to_user'.'entity_id' 
             INNER JOIN 'm2m_app'.'user' ON 'entity_to_user'.'user_id' = 'user'.'user_id' 
             WHERE (
                 ('device'.'device_id' = :APR0) 
                 AND ('entity_to_user'.'entity_type_id' = 10)
             ) AND ('user'.'user_id' = :user_id)
    [bind] => Array
        (
            [APR0] => 23482
            [user_id] => 1
        )

    [bindTypes] => Array
        (
        )
)

@niden
Copy link
Member

niden commented Oct 2, 2024

@alrieckert If you don't mind, can you add a line to the CHANGELOG regarding this?

After that I will merge it. Thank you so much

@niden niden added 5.0 The issues we want to solve in the 5.0 release bug A bug report status: medium Medium labels Oct 2, 2024
@niden niden merged commit d518c27 into phalcon:5.0.x Oct 21, 2024
42 checks passed
@niden
Copy link
Member

niden commented Oct 21, 2024

Thank you @alrieckert

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
5.0 The issues we want to solve in the 5.0 release bug A bug report status: medium Medium
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

2 participants