Skip to content

And/Or visitors break adding conditions to an On node #45

@dvandersluis

Description

@dvandersluis

The visitor for And/Or nodes is overridden in to_sql:

https://github.com/Faveod/arel-extensions/blob/master/lib/arel_extensions/visitors/to_sql.rb#L561-L579

However, this causes broken sql when adding a condition to an On node:

Arel::Nodes::On.new(Post.arel_table[:user_id].eq(User.arel_table[:id])).to_sql
=> "ON `posts`.`user_id` = `users`.`id`"

Arel::Nodes::On.new(Post.arel_table[:user_id].eq(User.arel_table[:id]))
  .and(Post.arel_table[:type].eq('foo')).to_sql
=> "(ON `posts`.`user_id` = `users`.`id`) AND (`posts`.`type` = 'foo')"

As you can see, the entire original ON got parenthesized, which leads to a SQL syntax error.

I'm using Rails 6.1.4.1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions