Closed roscom closed 1 year ago
ruby 2.6.6 rails 6.1.7.6
Hey @roscom, thanks for bringing this to my attention. It looks like what you want is Arel::Nodes::InfixOperation
eg:
Keyword.select(
[
Keyword.arel_table[:phrase],
SemrushRelatedKeyword.arel_table[:used_count],
Arel.star.count,
Arel::Nodes::InfixOperation.new(
'-', 3, SemrushRelatedKeyword.arel_table[:used_count]
) * Arel.star.count
]
).having(
SemrushRelatedKeyword.arel_table[:used_count].lt(3).and(Arel.star.count.eq(100))
).joins(
Keyword.arel_table.join(SemrushRelatedKeyword.arel_table).on(
SemrushRelatedKeyword.arel_table[:keyword_id].eq(Keyword.arel_table[:id])
).join_sources
).group(
Keyword.arel_table[:phrase], SemrushRelatedKeyword.arel_table[:used_count]
).limit(10)
I just pushed an update to scuttle.io that should do this correctly now, let me know if you're still having problems 😄
I have 2 tables and a join table
The following SQL works correctly
The equivalent rails code (markdown annotated) generated through scuttle is
The resulting error produced in rails console using ruby 2.6.6
NoMethodError (undefined method `-' for "3":Arel::Nodes::SqlLiteral)
Could you please advise the correct method to do the calculation?