I have two tables, user & provider and I''m struggling to set up the association between them. A simplified table structure for the two is: CREATE TABLE users ( id integer not null, login string not null, password string not null ) CREATE TABLE providers ( id integer not null, user_id integer not null, ... ) and I''ve used the generater to create two modules, as follows (cut down) class User < ActiveRecord::Base has_one :provider def invoices_raised provider.get_invoices end .... end class Provider < ActiveRecord::Base has_many :invoices belongs_to :user def get_invoices invoices.find(:all) end end I have a controller that calls invoices_raised : class AccountController < ApplicationController model :user before_filter :get_invoices def get_invoices @user = User.find(@session[''user''].id) @invoices_raised = @user.invoices_raised end ... end but inside the invoices_raised method I get the following error: You have a nil object when you didn''t expect it! The error occured while evaluating nil.get_invoices I thought that using belongs_to & has_one was supposed to implicitly create a provider instance for me? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---