Join and Refer In Tables

OK: I’ve read through this a million times and am still not getting it
right. I have two tables (posts and authors), with a one(author) to
many(posts) relationship, and the keys are not named id but user_name in
one and screen_name in the other. I’m trying to join the tables in the
model, then pull all fields from posts and one additional field from
author, bio. Here is my stuff:

in models/post.rb

class Post < ActiveRecord::Base
has_one :authors, :primary_key => :user_name, :foreign_key =>

in controllers/posts.rb

@postswithauthors = Post.find(:all, :limit => 20, :conditions =>“posted
between '”+@starthour+"’ and ‘"+@endhour+"’ and
searchterm=’"+searchterm+"’", :order => “posted DESC”, :include =>
:authors )

in the view/posts.rb

for x in @postswithauthors
puts x.user_name
puts x.posted

Every time I run this I get something like invalid method “bio”. Been
over and over all of the association docs and can’t find my error.
Please help.


“has_one” should only be used in one-to-one relationships.
This is a one-to-many relationship, so use “belongs_to :author,
:foreign_key => :screen_name” in the model, “:include => :author” in the
controller, and “” in the view.