Introduce an association between User and Event
Introduce an association between User and Event for the user schedule. As there was already a relation call users in Event the new relation is called public_users. And for the same reason the relation in Event is called public_events.
This commit is contained in:
parent
89af26bf18
commit
7f7375b7db
4 changed files with 19 additions and 0 deletions
|
|
@ -22,8 +22,11 @@ class Event < ActiveRecord::Base
|
|||
belongs_to :difficulty_level
|
||||
belongs_to :program
|
||||
|
||||
has_and_belongs_to_many :favourite_users, class_name: 'User'
|
||||
|
||||
accepts_nested_attributes_for :event_users, allow_destroy: true
|
||||
accepts_nested_attributes_for :users
|
||||
accepts_nested_attributes_for :favourite_users
|
||||
|
||||
before_create :generate_guid
|
||||
|
||||
|
|
|
|||
|
|
@ -49,6 +49,9 @@ class User < ActiveRecord::Base
|
|||
has_many :votes, dependent: :destroy
|
||||
has_many :voted_events, through: :votes, source: :events
|
||||
has_many :subscriptions, dependent: :destroy
|
||||
|
||||
has_and_belongs_to_many :favourite_events, class_name: 'Event'
|
||||
|
||||
accepts_nested_attributes_for :roles
|
||||
|
||||
scope :admin, -> { where(is_admin: true) }
|
||||
|
|
|
|||
8
db/migrate/20160811143427_create_events_users.rb
Normal file
8
db/migrate/20160811143427_create_events_users.rb
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
class CreateEventsUsers < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :events_users, id: false do |t|
|
||||
t.references :event
|
||||
t.references :user
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -243,6 +243,11 @@ ActiveRecord::Schema.define(version: 20170213145807) do
|
|||
t.datetime "created_at"
|
||||
end
|
||||
|
||||
create_table "events_users", id: false, force: :cascade do |t|
|
||||
t.integer "event_id"
|
||||
t.integer "user_id"
|
||||
end
|
||||
|
||||
create_table "lodgings", force: :cascade do |t|
|
||||
t.string "name"
|
||||
t.text "description"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue