New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

raise error "undefined method `arel_table'" in rails 5 #151

Closed
isuke opened this Issue May 18, 2017 · 1 comment

Comments

Projects
None yet
2 participants
@isuke

isuke commented May 18, 2017

Error of "undefined method `arel_table'" has raised when I did following test.

# spec/associations/active_record_extensions_spec.rb
describe "#belongs_to_active_hash" do
  context "setting by id" do
    it "finds the correct records" do
      School.belongs_to_active_hash :city
      city = City.create
      school = School.create :city_id => city.id
      School.find_by(city: city).should == city
    end
  end
end
[] % bundle exec rspec spec/associations/active_record_extensions_spec.rb:207
Run options: include {:locations=>{"./spec/associations/active_record_extensions_spec.rb"=>[207]}}
F

Failures:

  1) ActiveHash::Base active record extensions ActiveHash::Associations::ActiveRecordExtensions #belongs_to_active_hash setting by id 
     Failure/Error: School.find_by(city: city)
     NoMethodError:
       undefined method `arel_table' for City:Class
     # ./lib/active_hash/base.rb:274:in `method_missing'
     # ./spec/associations/active_record_extensions_spec.rb:207:in `block (5 levels) in <top (required)>'

Thank you.

@syguer

This comment has been minimized.

Show comment
Hide comment
@syguer

syguer May 18, 2017

Collaborator

School.find_by(city: city).should == city

School.find_by returns School instance. It is incorrect before an issue.

By the way, ActiveHash does not support arel behaviour. so you should do like this

 School.find_by(city_id: city.id).should be school

If you want to write like your sample, pull request is welcome 😄
Thanks.

Collaborator

syguer commented May 18, 2017

School.find_by(city: city).should == city

School.find_by returns School instance. It is incorrect before an issue.

By the way, ActiveHash does not support arel behaviour. so you should do like this

 School.find_by(city_id: city.id).should be school

If you want to write like your sample, pull request is welcome 😄
Thanks.

@syguer syguer closed this May 18, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment