# Problems with master-detail relationship

**URL:** <https://www.ruby-forum.com/t/problems-with-master-detail-relationship/204653>\
**Category:** Rails\
**Created:** [March 17, 2011, 6:30pm UTC](https://www.ruby-forum.com/t/problems-with-master-detail-relationship/204653 "2011-03-17T18:30:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [March 17, 2011, 6:30pm UTC](https://www.ruby-forum.com/t/problems-with-master-detail-relationship/204653/1 "2011-03-17T18:30:27Z")

</div>

I have two tables. Let say headers and details.

On headers\_controller.rb I have

has\_many :details

On details\_controller.rb I have

belongs\_to :header

I have in my model for header (just for testing):

def list  
@headers = Headers.sort( “headers.kind ASC”)  
end

So when i run after loading the proper data a header.details.size it  
returns me the number of details for the selected header.

But when I try to display header.details.size in a list view for the  
headers I get an arror saying  
“Unrecognized constant Header::Detail”

I try to get this in the list with:

\<%= header.details.size %\>

What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![rhin0nt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/6a8cbe/32.png) [@rhin0nt](https://www.ruby-forum.com/u/rhin0nt)\
**Post date:** [March 17, 2011, 6:41pm UTC](https://www.ruby-forum.com/t/problems-with-master-detail-relationship/204653/2 "2011-03-17T18:41:06Z")

</div>

On 17 March 2011 16:27, rhin0nt [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I have two tables. Let say headers and details.
> 
> On headers\_controller.rb I have
> 
> has\_many :details

That should be in the model not the controller

> On details\_controller.rb I have
> 
> belongs\_to :header

ditto

> I have in my model for header (just for testing):

This should be in the controller

> def list  
> @headers = Headers.sort( “headers.kind ASC”)

That should be Header (singular)

---

<div class="post-metadata">

**Author:** ![rhin0nt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/6a8cbe/32.png) [@rhin0nt](https://www.ruby-forum.com/u/rhin0nt)\
**Post date:** [March 17, 2011, 6:54pm UTC](https://www.ruby-forum.com/t/problems-with-master-detail-relationship/204653/3 "2011-03-17T18:54:55Z")

</div>

On 17 March 2011 17:39, Colin L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > On details\_controller.rb I have
> > 
> > def list  
> > @headers = Headers.sort( “headers.kind ASC”)
> 
> That should be Header (singular)

Also it should be order not sort

Colin
