所以我正在创建一个支持票务系统。
我需要一些关于从我的User
表创建团队的帮助,因此应用程序的用户可以为团队分配票证,并且一旦创建票证并且他们属于该团队,整个团队就可以收到电子邮件。
我有Department
,Ticket
和User
型号。
有什么想法吗?
答案 0 :(得分:2)
假设
以下类结构可以起作用:
class Department < ActiveRecord::Base
end
class Ticket < ActiveRecord::Base
belongs_to :team
end
class User < ActiveRecord::Base
belongs_to :team
end
class Team < ActiveRecord::Base
has_many :users
has_many :tickets
end
这允许以下内容:
t = Ticket.find(...) # Find a specific ticket with id
t.team # The team assigned to which the ticket is assigned to
t.team.users # Users belonging to that team
t.team.users.map(&:email) # Array of emails for the users belonging to that team, assuming there is an email field in the `User` model.