Skip to content
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

Merged
merged 4 commits into from
May 31, 2015

Conversation

hanlindev
Copy link
Contributor

No description provided.

course
creator
updater
name "group 1"

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.

@hanlindev
Copy link
Contributor Author

Dependency #140

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

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.

@allenwq allenwq force-pushed the hanlin/groups-model branch 3 times, most recently from 463f0a7 to d4042ea Compare May 15, 2015 04:01
@@ -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
Copy link
Member

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.

private

def user_and_group_in_same_course #:nodoc:
unless user.courses.include?(group.course)

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.

@allenwq allenwq force-pushed the hanlin/groups-model branch 2 times, most recently from c2ef135 to c31a709 Compare May 16, 2015 08:03
def change
create_table :course_groups do |t|
t.string :name, null: false, default: ''
t.belongs_to :course, null: false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

course before the name.

@allenwq
Copy link
Member

allenwq commented May 20, 2015

@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,
Copy link
Member

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

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
Copy link
Member

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK !

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]
Copy link
Member

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.

Copy link
Member

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.

@allenwq allenwq force-pushed the hanlin/groups-model branch 2 times, most recently from 992cfcf to e6d5c26 Compare May 27, 2015 16:38
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
Copy link
Member

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?

@allenwq allenwq force-pushed the hanlin/groups-model branch 3 times, most recently from 460cc62 to 301405d Compare May 29, 2015 17:26
@allenwq
Copy link
Member

allenwq commented May 29, 2015

@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?
Copy link
Member

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.

@allenwq
Copy link
Member

allenwq commented May 31, 2015

@lowjoel Can this be merged ?

lowjoel added a commit that referenced this pull request May 31, 2015
@lowjoel lowjoel merged commit f4852a0 into Coursemology:master May 31, 2015
@lowjoel lowjoel deleted the hanlin/groups-model branch June 8, 2015 11:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants