我想为团队分配团队负责人和成员(用户)。我已经在团队和用户表之间创建了“具有多个直通”关联,因为一个团队可能有很多用户,并且一个用户可以分配给多个团队。为了获得每个团队的团队领导,我将 team_lead 列放在了团队表中。
疑问: 1.在创建团队时,将 team_lead 列放入团队表中以将团队领导分配给团队是否正确。
- 创建团队时,它将有一个团队负责人和一些用户,这些用户已经存在于数据库中。如何将用户分配给团队?
用户.rb
class User < ActiveRecord::Base
has_many :teams, through: :user_teams
has_many :user_teams
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable,
# :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :username, :email, :password, :password_confirmation, :remember_me, :first_name, :last_name, :is_admin, :contact_no, :birth_date, :joining_date, :is_active, :is_hr, :is_manager
# attr_accessible :title, :body
end
团队.rb
class Team < ActiveRecord::Base
attr_accessible :name
has_many :user_teams
has_many :users, through: :user_teams
end
team_user.rb
class TeamsUser < ActiveRecord::Base
attr_accessible :team_id, :team_lead, :user_id
belongs_to :user
belongs_to :team
end
在创建团队时,我想将团队负责人和用户分配给团队。如何实现这一点。任何帮助,将不胜感激。谢谢。