has_many Association Troubles

Rails, Ruby

So I followed the simple example provided by Josh Susser’s New association goodness in Rails 1.1 but within my own models I can’t seem to get the connection to work.

I have a  <omitted>, a <omitted>, and a <omitted> join model. I want one <omitted> assigned to several <omitted> and a <omitted> can have several <omitted>…thus the need for the join table. I’m storing just the id’s for <omitted> and <omitted> in the join table as <omitted>_id and <omitted>_id. When I run <omitted>.connections.size I get the correct number of associations for that <omitted>.

The rub is I can’t do the rails magic of <omitted>.<omitted>.name – it get a huge error in the console instead of what I want the output to be.

Don’t worry I solved it…


One thought on “has_many Association Troubles

  1. Ok I figured it out
    class Relationship < ActiveRecord::Base
    belongs_to :station #<----------------not plural
    belongs_to :contact #<----------------not plural

    class Contact true
    has_many :station, :through => :relationships #<----station NOT PLURAL

    and lastly
    class Station true
    has_many :contact, :through => :relationships #<----contact NOT PLURAL

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s