Saturday, August 20, 2011

[Rails] Newbie: Different context and associations for one model

Hi I have models (User and Meeting) like this:


# == Schema Information
#
# Table name: users
#
# id :integer not null, primary key
# name :string(255)
# email :string(255)
# created_at :datetime
# updated_at :datetime
#

class User < ActiveRecord::Base
has_many :participations
has_many :meetings, :through => :participations
has_many :lectures, :class_name => "Meeting"
attr_accessible :name, :email
-----------------------------------------------------------------


and:

# == Schema Information
#
# Table name: meetings
#
# id :integer not null, primary key
# starts_at :datetime
# ends_at :datetime
# title :string(255)
# description :text
# place :string(255)
# tutor :string(255)
# total_places :integer
# google_event_id :string(255)
# google_sync_status :string(255)
# created_at :datetime
# updated_at :datetime
#
class Meeting < ActiveRecord::Base
# it allows tracking changes in models - see declaration of
validations
include ActiveModel::Dirty
has_many :participations
has_many :users, :through => :participations
belongs_to :tutor, :class_name => "User", :foreign_key => "user_id"
--------------------------------------------------


and then I can find a tutor for a meeting but not the lectures for the
user. Should I make a migration containing:
add_column :meetings :references, :user_id (or tutor_id) ???
Will appreciate any suggestions
Cheers

--
Posted via http://www.ruby-forum.com/.

--
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@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate