# Database relation's tying to pull data from another table

**URL:** <https://www.ruby-forum.com/t/database-relations-tying-to-pull-data-from-another-table/187769>\
**Category:** Rails\
**Created:** [April 29, 2010, 12:48am UTC](https://www.ruby-forum.com/t/database-relations-tying-to-pull-data-from-another-table/187769 "2010-04-29T00:48:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![KRKRKR](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/cab0a1/32.png) [@KRKRKR](https://www.ruby-forum.com/u/KRKRKR)\
**Post date:** [April 29, 2010, 12:48am UTC](https://www.ruby-forum.com/t/database-relations-tying-to-pull-data-from-another-table/187769/1 "2010-04-29T00:48:36Z")

</div>

I need some newb help here. I am making a quick app to learn on to  
hold my collection of cards. I have a card database with a ton of  
fields, and also a collection table. my collection has\_many cards,  
and cards belongs\_to collection. I’m trying to list out cards in my  
collection, and pulling the card “title” from the “card” database. I  
know my relation’s are setup because I can do this in other methods  
under my collection model, but I can’t seem to do the following, which  
I thought would pull the “title” with the according card\_id

\<% @collections.each do |c| %\>

- \<%= c.card.title %\>

I think I’m trying to do something the each do will not allow.

just as an fyi I can pull everything from my collection table ie:  
c.card\_id or c.qty etc… but trying to tap in to the other table it  
bawks.

Cheers

---

<div class="post-metadata">

**Author:** ![KRKRKR](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/cab0a1/32.png) [@KRKRKR](https://www.ruby-forum.com/u/KRKRKR)\
**Post date:** [April 29, 2010, 4:32pm UTC](https://www.ruby-forum.com/t/database-relations-tying-to-pull-data-from-another-table/187769/2 "2010-04-29T16:32:48Z")

</div>

You need to add another loop for the cards:

\<% @collections.each do |collection| %\>  
\<% collection.cards.each do |card| %\>

- \<%= card.title %\>

---

<div class="post-metadata">

**Author:** ![KRKRKR](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/cab0a1/32.png) [@KRKRKR](https://www.ruby-forum.com/u/KRKRKR)\
**Post date:** [April 29, 2010, 4:40pm UTC](https://www.ruby-forum.com/t/database-relations-tying-to-pull-data-from-another-table/187769/3 "2010-04-29T16:40:25Z")

</div>

Thx I figured it was something that simple
