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

SQL negating a LIKE doesn't appear to be generating correct arel code #19

Open
roscom opened this issue Oct 5, 2023 · 0 comments
Open

Comments

@roscom
Copy link

roscom commented Oct 5, 2023

SELECT clients.*  FROM clients  
    INNER JOIN roles ON roles.roleable_type = 'Client' AND roles.roleable_id = clients.id  
    INNER JOIN participants ON participants.expired_on IS NULL AND participants.id = roles.participant_id  
    WHERE participants.expired_on IS NULL AND roles.expired_on IS NULL AND NOT ((participants.name_search LIKE '%tway%' OR participants.name_search LIKE '%legal%')) order by short_name;

produces the following arel code:

Client.select(Client.arel_table[Arel.star]).where(
  Participant.arel_table[:expired_on].eq(nil).and(
    Role.arel_table[:expired_on].eq(nil).and(
      Participant.arel_table[:name_search].or(Participant.arel_table[:name_search])
    )
  )
).joins(
  Client.arel_table.join(Role.arel_table).on(
    Role.arel_table[:roleable_type].eq('Client').and(
      Role.arel_table[:roleable_id].eq(Client.arel_table[:id])
    )
  ).join_sources
).joins(
  Client.arel_table.join(Participant.arel_table).on(
    Participant.arel_table[:expired_on].eq(nil).and(
      Participant.arel_table[:id].eq(Role.arel_table[:participant_id])
    )
  ).join_sources
).order(:short_name)

The match method is omitted from

Participant.arel_table[:name_search].or(Participant.arel_table[:name_search]

It should be

Participant.arel_table[:name_search].matches(%tway%).or(Participant.arel_table[:name_search].matches('%legal%')

I would appreciate it if you could take a look and let me know what I may have done incorrectly or if it's Scuttle

@roscom roscom changed the title SQL negating a LIKE don't appear to be generating correct arel code SQL negating a LIKE doesn't appear to be generating correct arel code Oct 5, 2023
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

1 participant