Rails: Design Pattern to Store Order of Relations
Posted
by ChrisInCambo
on Stack Overflow
See other posts from Stack Overflow
or by ChrisInCambo
Published on 2010-05-12T14:50:53Z
Indexed on
2010/05/12
14:54 UTC
Read the original article
Hit count: 226
Hi,
I have four models: Customer, QueueRed, QueueBlue, QueueGreen.
The Queue models have a one to many relationship with customers
A customer must always be in a queue
A customer can only be in one queue at a time
A customer can change queues
We must be able to find out the customers current position in their respective queue
In an object model the queues would just have an array property containing customers, but ActiveRecord doesn't have arrays.
In a DB I would probably create some extra tables just to handle the order of the stories in the queue.
My question is what it the best way to model the relationship in ActiveRecord? Obviously there are many ways this could be done, but what is the best or the most in line with how ActiveRecord should be used?
Cheers,
Chris
© Stack Overflow or respective owner