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

Alias replacement not taking account multiple lines #38

Open
talski opened this issue Jan 23, 2023 · 2 comments
Open

Alias replacement not taking account multiple lines #38

talski opened this issue Jan 23, 2023 · 2 comments

Comments

@talski
Copy link

talski commented Jan 23, 2023

I'm using snake case, when using multiple lines ``, sometimes the column/table alias do not get replaced.

The first myModel.studentId, just before the or, do not get replaced in this example

this will not work

.innerJoin(MyModel, 'myModel', 'myModel.foreignId = another.foreignId')
.leftJoin(
  Message,
  'msg',
  `
  msg.receiverType = :userType and msg.receiverId = :userId and
  msg.senderType = 'Something' and msg.senderId = myModel.studentId
  or
  msg.receiverType = 'Something' and msg.receiverId = myModel.studentId and
  msg.senderType = :userType and msg.senderId = :userId
`
)

this one will

.innerJoin(MyModel, 'myModel', 'myModel.foreignId = another.foreignId')
.leftJoin(
  Message,
  'msg',
  `
  msg.receiverType = :userType and msg.receiverId = :userId and
  msg.senderType = 'Something' and msg.senderId = myModel.studentId or
  msg.receiverType = 'Something' and msg.receiverId = myModel.studentId and
  msg.senderType = :userType and msg.senderId = :userId
`
)

using .replace(/\s+/g, ' ') will also work

@akashjobanputra
Copy link

@talski I'm facing a similar issue, did you find a way to fix the issue?

@talski
Copy link
Author

talski commented Jun 25, 2024

@akashjobanputra I'm just removing the spaces before running the query

.innerJoin(MyModel, 'myModel', 'myModel.foreignId = another.foreignId')
.leftJoin(
  Message,
  'msg',
  `
  msg.receiverType = :userType and msg.receiverId = :userId and
  msg.senderType = 'Something' and msg.senderId = myModel.studentId or
  msg.receiverType = 'Something' and msg.receiverId = myModel.studentId and
  msg.senderType = :userType and msg.senderId = :userId
`.replace(/\s+/g, ' ')
)

putting this code .replace(/\s+/g, ' ') will replace all new lines with a simple space

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

No branches or pull requests

2 participants