camertron / scuttle-rb

A library for transforming raw SQL statements into ActiveRecord/Arel queries. Ruby wrapper and tests for scuttle-java.
86 stars 2 forks source link

odd generated code for query with sub-query select #12

Closed roscom closed 4 years ago

roscom commented 4 years ago

Hi

rails 6.0.1 mysql query select * from client_blog_allocations where allocation_id = 12 and role_id = 76 and blog_id in (select id from blogs where state in ('deployed', 'suspended'));

Scuttle generates: ClientBlogAllocation.select(Arel.star).where( ClientBlogAllocation.arel_table[:allocation_id].eq(12).and( ClientBlogAllocation.arel_table[:role_id].eq(76).and( ClientBlogAllocation.arel_table[:blog_id].in( Blog.select(:id).where( Blog.arel_table[:state].in(['deployed', 'suspended']) ).ast ) ) ) )

results in at runtime: NoMethodError: undefined method `ast' for #<ActiveRecord::Relation []> Did you mean? last

Any suggestions?

camertron commented 4 years ago

Hey @roscom, thanks for the bug report. It looks like the #ast method was deprecated in Rails 5.2 and removed in 6.0. I've added a dropdown version selector to scuttle.io that should remove the errant .ast bit for Rails >= 6.0 and leave it in for Rails < 6.0. Feel free to give it a spin, but the tldr is to simply remove .ast from your code.

NOTE: You may have to hard-refresh to pick up the JS changes on scuttle.io