# Confused setting up relationships

**URL:** <https://www.ruby-forum.com/t/confused-setting-up-relationships/122334>\
**Category:** Rails\
**Created:** [December 6, 2007, 6:56pm UTC](https://www.ruby-forum.com/t/confused-setting-up-relationships/122334 "2007-12-06T18:56:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 6, 2007, 6:56pm UTC](https://www.ruby-forum.com/t/confused-setting-up-relationships/122334/1 "2007-12-06T18:56:16Z")

</div>

Hi everyone,

I am working on a new project which will implement a bracket based  
tournament system, like the NCAA finals. The entrants will be  
assigned to brackets, users will vote, the winner goes on, the looser  
goes home. 🙂 I am having a little difficulty setting up the  
relationships for my objects.

So far I have the following objects in mind…

Tournament = The overall container that will define the parameters of  
the tournament.  
Round = One of the individual one-on-one contests between two teams.  
Entry = Details on the team itself.  
Vote = User votes cast during each round

The associations I have in mind are:

Tournament \<\<  
has\_many :rounds

Round \<\<  
belongs\_to :tournament  
has\_many :entries

Entry \<\<  
belongs\_to :round  
has\_many :votes

Vote \<\<  
belongs\_to :entry

So far so good… but I also need to associate the vote with the  
round. Each entry will have lots of votes, but the votes from one  
round shouldn’t count towards the next round. I thought about:

Round \<\< has\_many :votes, :through =\> :entries

But that didn’t seem quite right.

Any help provided will be greatly appreciated. As an aside, does  
anyone know of any good resources (on-line or print) for getting my  
head around this kind of thinking? For some reason I just never seem  
to get my associations right, and I think it has more to do with not  
having the fundamentals down (unspecific to rails).

Thanks!

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 6, 2007, 7:08pm UTC](https://www.ruby-forum.com/t/confused-setting-up-relationships/122334/2 "2007-12-06T19:08:00Z")

</div>

Hi Andrew,

Just a quick thought…

On Dec 6, 2007, at 11:55 AM, removed\_email\_address@domain.invalid wrote:

> So far I have the following objects in mind…
> 
> Tournament = The overall container that will define the parameters of  
> the tournament.  
> Round = One of the individual one-on-one contests between two teams.  
> Entry = Details on the team itself.  
> Vote = User votes cast during each round

I’d probably say that a “Round” is a collection of “Contest”, the  
contest being between two teams. So a Tournament has many rounds  
(Sweet Sixteen, Elite Eight, Final Four, etc), and a Round has many  
contests, and a contest has many (well, two) entries.

Peace,  
Phillip

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 6, 2007, 8:39pm UTC](https://www.ruby-forum.com/t/confused-setting-up-relationships/122334/3 "2007-12-06T20:39:23Z")

</div>

Phillip K. wrote:

> Hi Andrew,
> 
> Just a quick thought…
> 
> On Dec 6, 2007, at 11:55 AM, removed\_email\_address@domain.invalid wrote:
> 
> > So far I have the following objects in mind…
> > 
> > Tournament = The overall container that will define the parameters of  
> > the tournament.  
> > Round = One of the individual one-on-one contests between two teams.  
> > Entry = Details on the team itself.  
> > Vote = User votes cast during each round
> 
> I’d probably say that a “Round” is a collection of “Contest”, the  
> contest being between two teams. So a Tournament has many rounds  
> (Sweet Sixteen, Elite Eight, Final Four, etc), and a Round has many  
> contests, and a contest has many (well, two) entries.
> 
> Peace,  
> Phillip

here is help on associations. let me know what you think or if it  
helps.

[http://gemblon.com/railshowto/?p=19#more-19](http://gemblon.com/railshowto/?p=19#more-19)
