sergserg
sergserg

Reputation: 22264

has_many with two or more tables.

I'm trying to add multiple has_many relationships to my model:

class Program < ActiveRecord::Base
  has_many :courses, :program_offers
  belongs_to :university
  attr_accessible :end_date, :name, :period, :start_date, :symbol, :year, :university_id, :description, :titles, :profile, :price
end

But I get:

hash expected error.

How can I reference two has many tables?

Upvotes: 0

Views: 29

Answers (1)

Rahul Tapali
Rahul Tapali

Reputation: 10137

You can't do that because it is association method which takes only one association name as argument:

  has_many(name, options = {}, &extension)

So specify each association in single line.

  has_many :courses
  has_many :program_offers

If you specify like that it considers that you are specifying some condition or block. See the API doc http://apidock.com/rails/ActiveRecord/Associations/ClassMethods/has_many

Upvotes: 2

Related Questions