-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Course::Group and Course::GroupUser #161
Add Course::Group and Course::GroupUser #161
Conversation
course | ||
creator | ||
updater | ||
name "group 1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer single-quoted strings when you don't need string interpolation or special symbols.
Dependency #140 |
7f29d55
to
7d2e023
Compare
stampable | ||
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Align the elements of a hash literal if they span more than one line.
463f0a7
to
d4042ea
Compare
@@ -13,6 +13,8 @@ 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, inverse_of: :course, dependent: :destroy, class_name: Course::Group.name | |||
has_many :group_users, through: :groups |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this association makes sense.
d4042ea
to
bc8ec5f
Compare
private | ||
|
||
def user_and_group_in_same_course #:nodoc: | ||
unless user.courses.include?(group.course) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use a guard clause instead of wrapping the code inside a conditional expression.
c2ef135
to
c31a709
Compare
def change | ||
create_table :course_groups do |t| | ||
t.string :name, null: false, default: '' | ||
t.belongs_to :course, null: false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
course before the name.
c31a709
to
1226b97
Compare
@lowjoel Can you review this again ? thanks ! |
class Course::Group < ActiveRecord::Base | ||
stampable | ||
belongs_to :course, inverse_of: :groups | ||
has_many :group_users, inverse_of: :group, dependent: :destroy, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need the foreign_key
key?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lowjoel Thanks ! It does not need the foreign_key here and I've removed it. However, we need to specify the foreign_key in group_users side.
@@ -11,6 +11,9 @@ class User < ActiveRecord::Base | |||
has_many :instances, through: :instance_users | |||
has_many :course_users, inverse_of: :user, dependent: :destroy | |||
has_many :courses, through: :course_users | |||
has_many :course_group_users, inverse_of: :user, dependent: :destroy, | |||
class_name: Course::GroupUser.name | |||
has_many :groups, through: :course_group_users |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be :course_groups
, with an alias on Course::GroupUser
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK !
64eb1fb
to
c15ccd5
Compare
create_table :course_group_users do |t| | ||
t.belongs_to :course_group, null: false | ||
t.belongs_to :user, null: false | ||
t.integer :role, null: false, default: Course::GroupUser.roles[:normal] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By right this should be a constant 0, but okay.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
set defaults in the model, then.
992cfcf
to
e6d5c26
Compare
e6d5c26
to
1982920
Compare
belongs_to :course, inverse_of: :groups | ||
has_many :group_users, inverse_of: :course_group, dependent: :destroy, | ||
class_name: Course::GroupUser.name | ||
has_many :users, through: :group_users |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
empty name validation, no default owner?
1982920
to
636cb80
Compare
460cc62
to
301405d
Compare
@lowjoel I've updated here, Added a new unique index on group_name and course_id |
class Course::Group < ActiveRecord::Base | ||
stampable | ||
|
||
before_validation :set_defaults, if: :new_record? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
after_initialize
and before_validate
, and allow it to run twice. Sometimes not all the arguments are given at initialise.
301405d
to
4ee7baa
Compare
@lowjoel Can this be merged ? |
Add Course::Group and Course::GroupUser
No description provided.