jeudi 28 avril 2016

Rails - Many to many methods

So in my rails app there are lots of events and I want a user to be able to create a calendar of their own composed of the events. My current code is below, but I cannot use User.events or User.user_calendar at all and from my understanding of rails associations this shouldn't be a problem.

event.rb

has_and_belongs_to_many :days
has_many :user_calendars
has_many :users, through: :user_calendars

user.rb

has_many :user_calendars
has_many :events, through: :user_calendars

user_calendar.rb

belongs_to :users
belongs_to :event

migration.rb

create_table :user_calendars do |t|
  t.integer :user_id
  t.integer :event_id
  t.timestamps null: false
end

I simply want to be able to create a list of events unique to each user, but obviously any updates on a given event must be reflected on that event if it is within an user calendar.

Aucun commentaire:

Enregistrer un commentaire