oddcamp / active_hash_relation

ActiveHash Relation: Simple gem that allows you to run multiple ActiveRecord::Relation using hash. Perfect for APIs.
https://www.kollegorna.se/
MIT License
118 stars 15 forks source link

Conflict with ActiveRecord::Enum #20

Closed PabloMD closed 7 years ago

PabloMD commented 7 years ago

After gem install I start receiving error:

ActionView::Template::Error (undefined method `where' for #)

code example: Model

class Payment < ApplicationRecord
  enum payment_type: {dotpay: 1, bank_transfer: 4 }
end

then:

Payment.dotpay raises the exception above

vasilakisfil commented 7 years ago

Thanks for the info. I will take a look in the following days!

vasilakisfil commented 7 years ago

@PabloMD I didn't find any issue, but I am adding tests not to feat/tests branch just to be sure.

demural commented 7 years ago

@vasilakisfil, I do not have time to investigate it further right now. Here's what I get on rails console just in case you are curious:-)

2.3.1 :001 > Payment.dotpay
NoMethodError: undefined method `where' for #<Module:0x000000064c8848>
        from /home/pablo/.rvm/gems/ruby-2.3.1@glakso5/gems/activerecord-5.0.0.1/lib/active_record/enum.rb:193:in `block (4 levels) in enum'
        from /home/pablo/.rvm/gems/ruby-2.3.1@glakso5/gems/active_hash_relation-1.1.0/lib/active_record/scope_names.rb:22:in `block (2 levels) in scope'
        from /home/pablo/.rvm/gems/ruby-2.3.1@glakso5/gems/activerecord-5.0.0.1/lib/active_record/relation.rb:351:in `scoping'
        from /home/pablo/.rvm/gems/ruby-2.3.1@glakso5/gems/active_hash_relation-1.1.0/lib/active_record/scope_names.rb:22:in `block in scope'
        from (irb):1
        from /home/pablo/.rvm/gems/ruby-2.3.1@glakso5/gems/railties-5.0.0.1/lib/rails/commands/console.rb:65:in `start'
        from /home/pablo/.rvm/gems/ruby-2.3.1@glakso5/gems/railties-5.0.0.1/lib/rails/commands/console_helper.rb:9:in `start'
        from /home/pablo/.rvm/gems/ruby-2.3.1@glakso5/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:78:in `console'
        from /home/pablo/.rvm/gems/ruby-2.3.1@glakso5/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
        from /home/pablo/.rvm/gems/ruby-2.3.1@glakso5/gems/railties-5.0.0.1/lib/rails/commands.rb:18:in `<top (required)>'
        from bin/rails:9:in `require'
        from bin/rails:9:in `<main>'
vasilakisfil commented 7 years ago

@PabloMD I added some test cases with enums, I don't see any conflict anywhere. Are you sure it comes from ActiveHashRelation ?

PabloMD commented 7 years ago

@vasilakisfil, hi the previous reply is from my company account:-), and it looks that the problem lies in resolving scope by ActiveHashRelation. In your added test case you actualy query DB by column and its value which works, I have tested it too (Payment.where(payment_type: 1)), but when you use Payment.dotpay it should translate it to same query ('Payment.where(payment_type: 1)').

... from /home/pablo/.rvm/gems/ruby-2.3.1@glakso5/gems/active_hash_relation-1.1.0/lib/active_record/scope_names.rb:22:in `block (2 levels) in scope'

vasilakisfil commented 7 years ago

Thanks for reporting. I have fixed it on master. Some notes:

Closing for now, feel free to reopen.