Skip to content

MJoin with inner LeftJoin, does not put LeftJoin at end. #15

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

Open
VictorioBerra opened this issue May 1, 2024 · 1 comment · May be fixed by #22
Open

MJoin with inner LeftJoin, does not put LeftJoin at end. #15

VictorioBerra opened this issue May 1, 2024 · 1 comment · May be fixed by #22

Comments

@VictorioBerra
Copy link

RE: https://datatables.net/forums/discussion/78882/editor-net-mjoin-leftjoin#latest

I think this is a legit bug.

// ...
  .MJoin(new MJoin("InventoryServerWarranty")
      .Set(false)
      .Link("InventoryServer.Id", "InventoryServerInventoryServerWarrantyLine.InventoryServerId")
      .Link("InventoryServerWarranty.Id", "InventoryServerInventoryServerWarrantyLine.InventoryServerWarrantyId")
      .Order("InventoryServerWarranty.CertificateNumber")
      .Model<Warranty>()
      .LeftJoin("InventoryServerWarrantyProvider", "InventoryServerWarrantyProvider.Id", "=", "InventoryServerWarranty.InventoryServerWarrantyProviderId")
  )
// ...

The Editor generated SQL looks like so:

SELECT
    DISTINCT [InventoryServer].[Id] as 'dteditor_pkey',
    [InventoryServerWarranty].[CertificateNumber] as 'CertificateNumber',
    [InventoryServerWarranty].[RegistrationID] as 'RegistrationID',
    [InventoryServerWarranty].[Notes] as 'Notes',
    [InventoryServerWarranty].[DeliveryDate] as 'DeliveryDate',
    [InventoryServerWarranty].[ExpirationDate] as 'ExpirationDate',
    [InventoryServerWarranty].[InventoryServerWarrantyProviderId] as 'InventoryServerWarrantyProviderId',
    [InventoryServerWarranty].[RetiredIncidentNumber] as 'RetiredIncidentNumber',
    [InventoryServerWarranty].[RetiredOn] as 'RetiredOn'
FROM
    [InventoryServer]
    LEFT JOIN [InventoryServerWarrantyProvider] ON [InventoryServerWarrantyProvider].[Id] = [InventoryServerWarranty].[InventoryServerWarrantyProviderId]
    JOIN [InventoryServerInventoryServerWarrantyLine] ON [InventoryServer].[Id] = [InventoryServerInventoryServerWarrantyLine].[InventoryServerId]
    JOIN [InventoryServerWarranty] ON [InventoryServerWarranty].[Id] = [InventoryServerInventoryServerWarrantyLine].[InventoryServerWarrantyId]
WHERE
    [InventoryServer].[Id] IN (2)
ORDER BY
    [InventoryServerWarranty].[CertificateNumber]

Note how that left join is FIRST. That will not work. Only by pulling that down to the be the final join, does the code work.

@AllanJard
Copy link
Contributor

Thanks for flagging this up. I'll take a look into it - agreed that the order needs to be changed.

@VictorioBerra VictorioBerra linked a pull request May 7, 2024 that will close this issue
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 a pull request may close this issue.

2 participants