# Nil when calling joins method on Model

**URL:** <https://www.ruby-forum.com/t/nil-when-calling-joins-method-on-model/195177>\
**Category:** Rails\
**Created:** [September 18, 2010, 11:33am UTC](https://www.ruby-forum.com/t/nil-when-calling-joins-method-on-model/195177 "2010-09-18T11:33:31Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jeff\_Gonzalez](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/65b543/32.png) [@Jeff\_Gonzalez](https://www.ruby-forum.com/u/Jeff_Gonzalez)\
**Post date:** [September 18, 2010, 11:33am UTC](https://www.ruby-forum.com/t/nil-when-calling-joins-method-on-model/195177/1 "2010-09-18T11:33:31Z")

</div>

I am trying to call the joins method on my model, but whenever I do,  
it always returns nil.

I have the following database schema:

# ======================== ==== Host ====

id int  
hostname nvarchar(50)

# ======================== ==== Lsa ====

id int  
host\_id int  
name nvachar(50)  
email nvarchar(255)

I have the following model:

# Host.rb

class Host \< ActiveRecord::Base  
set\_table\_name “systems.hosts”  
has\_one :lsainfo, :class\_name =\> “LsaInfo”  
end

# LsaInfo.rb

class LsaInfo \< ActiveRecord::Base  
set\_table\_name “consolecheck.lsainfo”  
belongs\_to :host, :class\_name =\> “Host”, :foreign\_key =\>  
“host\_id”, :primary\_key =\> “id”  
end

I am using rails 3.0.0 and executing commands from the rails  
console. I am able to access the relations (I think this is the  
correct term) with no problems, but as soon as I try to use joins, it  
becomes a problem and I get a nil error.

Loading development environment (Rails 3.0.0)

> > Host.first.lsainfo  
> > =\> #\<LsaInfo id: 28, host\_id: 6, name:“Jeff Gonzalez”, email:  
> > “removed\_email\_address@domain.invalid”\>

> > LsaInfo.first.host  
> > =\> #\<Host id: 51, hostname: “db”\>

> > LsaInfo.joins(:host).to\_sql  
> > NoMethodError: undefined method `eq' for nil:NilClass from /Users/jeff/.gem/ruby/1.8/gems/activesupport-3.0.0/lib/ active_support/whiny_nil.rb:48:in `method\_missing’  
> > from /Users/jeff/.gem/ruby/1.8/gems/activerecord-3.0.0/lib/  
> > active\_record/associations.rb:2176:in `association_join' from /Users/jeff/.gem/ruby/1.8/gems/activerecord-3.0.0/lib/ active_record/relation/query_methods.rb:209:in `build\_joins’  
> > from /Users/jeff/.gem/ruby/1.8/gems/activerecord-3.0.0/lib/  
> > active\_record/relation/query\_methods.rb:204:in `each' from /Users/jeff/.gem/ruby/1.8/gems/activerecord-3.0.0/lib/ active_record/relation/query_methods.rb:204:in `build\_joins’  
> > from /Users/jeff/.gem/ruby/1.8/gems/activerecord-3.0.0/lib/  
> > active\_record/relation/query\_methods.rb:138:in `build_arel' from /Users/jeff/.gem/ruby/1.8/gems/activerecord-3.0.0/lib/ active_record/relation/query_methods.rb:110:in `arel’  
> > from /Users/jeff/.gem/ruby/1.8/gems/activerecord-3.0.0/lib/  
> > active\_record/relation.rb:316:in `to\_sql’  
> > from (irb):6

Obviously I am not sure where my problem is occurring, or why things  
are going wrong. I created a new rails project, and created the  
category, post, comments, guest tables according to the Active Record  
Query Interface documentation (found here:  
[Active Record Query Interface — Ruby on Rails Guides](http://edgeguides.rubyonrails.org/active_record_querying.html#using-array-hash-of-named-associations)).  
Once I added in some data, everything worked fine and I was able to  
use the joins functionality without any issue in my new rails  
project. However, I am still unable to get it working in my current  
“real” project.

Any ideas on what I could be doing wrong?
