rubysherpas / paranoia

acts_as_paranoid for Rails 5, 6 and 7
Other
2.89k stars 529 forks source link

`.to_sql` does not work with joined paranoia model: Undefined method 'relation' for Arel::Nodes::BindParam #496

Open Laykou opened 4 years ago

Laykou commented 4 years ago

1) .to_sql method works without acts_as_paranoid 2) Calling the .to_sql on the User model without joins works as well:

> User.all.to_s
=> "SELECT \"users\".* FROM \"users\" WHERE \"users\".\"deleted_at\" IS NULL" 
  1. But calling .to_sql with joins on the paranoia model throws:
NoMethodError (undefined method 'relation' for #<Arel::Nodes::BindParam:0x00007f91ece6e120>)

How to reproduce:

class User < ApplicationRecord
  acts_as_paranoid
end

class UserSetting < ApplicationRecord
  belongs_to :user
end

UserSetting.joins(:user).to_sql

# NoMethodError (undefined method 'relation' for #<Arel::Nodes::BindParam:0x00007f91ece6e120>)