# Relationships quickie

**URL:** <https://www.ruby-forum.com/t/relationships-quickie/157103>\
**Category:** Rails\
**Created:** [January 7, 2009, 12:13pm UTC](https://www.ruby-forum.com/t/relationships-quickie/157103 "2009-01-07T12:13:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dnstevenson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8dc957/32.png) [@dnstevenson](https://www.ruby-forum.com/u/dnstevenson)\
**Post date:** [January 7, 2009, 12:13pm UTC](https://www.ruby-forum.com/t/relationships-quickie/157103/1 "2009-01-07T12:13:41Z")

</div>

i have a project.

the project has a status\_id.

i have a statuses table with id’s and names.

the project model includes “has\_one :status”

the status model includes “has\_many :projects”

in my projects index page instead of project.status\_id displaying 1, 2  
or 3 i want to have the statuses.name accosiated with that id.

i tied putting \<%= project.status.name %\> but i get the error,

SQLite3::SQLException: no such column: statuses.project\_id: SELECT \*  
FROM “statuses” WHERE (“statuses”.project\_id = 6) LIMIT 1

it appears to be looking in statuses table for project\_id not the other  
way around.

can anyone clear this up for me?

cheers,

dave

---

<div class="post-metadata">

**Author:** ![dnstevenson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8dc957/32.png) [@dnstevenson](https://www.ruby-forum.com/u/dnstevenson)\
**Post date:** [January 7, 2009, 12:19pm UTC](https://www.ruby-forum.com/t/relationships-quickie/157103/2 "2009-01-07T12:19:38Z")

</div>

Yeah, that is the way that the associations work.

if a model ‘has\_one’ of something, then the something has the foreign  
key  
relationship back.

It is described fairly nicely here:

> **[rails.info](http://guides.rails.info/association_basics.html)**
>
> Ruby on Rails,Rails Tutorial,Ruby Basics,Rails 4,Bar Rails,Rail

Simon

On Wed, 07 Jan 2009 20:13:41 +0900, Dave S.

---

<div class="post-metadata">

**Author:** ![dnstevenson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8dc957/32.png) [@dnstevenson](https://www.ruby-forum.com/u/dnstevenson)\
**Post date:** [January 7, 2009, 12:20pm UTC](https://www.ruby-forum.com/t/relationships-quickie/157103/3 "2009-01-07T12:20:13Z")

</div>

On Wed, Jan 7, 2009 at 12:13 PM, Dave S.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> i have a project.
> 
> the project has a status\_id.
> 
> i have a statuses table with id’s and names.
> 
> the project model includes “has\_one :status”

try belongs\_to :status

---

<div class="post-metadata">

**Author:** ![dnstevenson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8dc957/32.png) [@dnstevenson](https://www.ruby-forum.com/u/dnstevenson)\
**Post date:** [January 7, 2009, 12:31pm UTC](https://www.ruby-forum.com/t/relationships-quickie/157103/4 "2009-01-07T12:31:45Z")

</div>

Franz S. wrote:

> On Wed, Jan 7, 2009 at 12:13 PM, Dave S.  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > i have a project.
> > 
> > the project has a status\_id.
> > 
> > i have a statuses table with id’s and names.
> > 
> > the project model includes “has\_one :status”
> 
> try belongs\_to :status

i understand now! cheers guys
