# How to model user-ticket + staff-ticket relationship?

**URL:** <https://www.ruby-forum.com/t/how-to-model-user-ticket-staff-ticket-relationship/115855>\
**Category:** Rails\
**Created:** [September 29, 2007, 9:03am UTC](https://www.ruby-forum.com/t/how-to-model-user-ticket-staff-ticket-relationship/115855 "2007-09-29T09:03:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dacbo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b9e5f3/32.png) [@dacbo](https://www.ruby-forum.com/u/dacbo)\
**Post date:** [September 29, 2007, 9:03am UTC](https://www.ruby-forum.com/t/how-to-model-user-ticket-staff-ticket-relationship/115855/1 "2007-09-29T09:03:13Z")

</div>

I’m planning out an application that will involve creating tickets and  
assigning one or more staff to handle them, but I have a question about  
the correct way to structure the relationships in Activerecord

The application is made up of Members and Staff, which are subtypes of  
an STI User model. Either type of user can create a Ticket, but only  
Staff can be assigned to them.

Here’s what I have so far, but I’m not sure if it created an infinite  
loop

User::Member  
has\_many :tickets

User::Staff  
has\_many :tickets  
has\_many :tickets through :ticket\_assignments

Ticket  
belongs\_to :user  
has\_many :staff through :ticket\_assignments

TicketAssignment  
belongs\_to :ticket  
belongs\_to :staff

I have a feeling that the STI model for both User types is going to be  
the kink in the chain. Should I break it out? Is there another way to  
model this? Should I go with a habtm join instead?

Thanks!

---

<div class="post-metadata">

**Author:** ![dacbo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b9e5f3/32.png) [@dacbo](https://www.ruby-forum.com/u/dacbo)\
**Post date:** [October 1, 2007, 4:01pm UTC](https://www.ruby-forum.com/t/how-to-model-user-ticket-staff-ticket-relationship/115855/2 "2007-10-01T16:01:35Z")

</div>

Still looking for help on this one. I submitted it late Friday night  
(EST), so wanted to bump it for the Monday morning crowd. The full text  
is below.

Thanks.

Chris B. wrote:

> I’m planning out an application that will involve creating tickets and  
> assigning one or more staff to handle them, but I have a question about  
> the correct way to structure the relationships in Activerecord
> 
> The application is made up of Members and Staff, which are subtypes of  
> an STI User model. Either type of user can create a Ticket, but only  
> Staff can be assigned to them.
> 
> Here’s what I have so far, but I’m not sure if it created an infinite  
> loop
> 
> User::Member  
> has\_many :tickets
> 
> User::Staff  
> has\_many :tickets  
> has\_many :tickets through :ticket\_assignments
> 
> Ticket  
> belongs\_to :user  
> has\_many :staff through :ticket\_assignments
> 
> TicketAssignment  
> belongs\_to :ticket  
> belongs\_to :staff
> 
> I have a feeling that the STI model for both User types is going to be  
> the kink in the chain. Should I break it out? Is there another way to  
> model this? Should I go with a habtm join instead?
> 
> Thanks!
