Skip to content

Commit

Permalink
Add inverse_of to all the relations
Browse files Browse the repository at this point in the history
  • Loading branch information
allenwq committed May 15, 2015
1 parent ff77dab commit 463f0a7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/models/course.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Course < ActiveRecord::Base
has_many :announcements, inverse_of: :course, dependent: :destroy
has_many :achievements, inverse_of: :course, dependent: :destroy
has_many :levels, inverse_of: :course, dependent: :destroy
has_many :groups, dependent: :destroy, class_name: Course::Group.name
has_many :groups, inverse_of: :course, dependent: :destroy, class_name: Course::Group.name
has_many :group_users, through: :groups

delegate :staff, to: :course_users
Expand Down
8 changes: 3 additions & 5 deletions app/models/course/group.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
class Course::Group < ActiveRecord::Base
stampable
belongs_to :course
has_many :group_users,
dependent: :destroy,
class_name: Course::GroupUser.name,
foreign_key: :course_group_id
belongs_to :course, inverse_of: :groups
has_many :group_users, inverse_of: :group, dependent: :destroy,
class_name: Course::GroupUser.name, foreign_key: :course_group_id

# Add the given user to this group.
#
Expand Down
5 changes: 3 additions & 2 deletions app/models/course/group_user.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
class Course::GroupUser < ActiveRecord::Base
stampable
belongs_to :user
belongs_to :group, class_name: Course::Group.name, foreign_key: :course_group_id
belongs_to :user, inverse_of: :group_users
belongs_to :group, class_name: Course::Group.name, inverse_of: :group_users,
foreign_key: :course_group_id

enum role: { normal: 0, manager: 1 }

Expand Down

0 comments on commit 463f0a7

Please sign in to comment.