# Has\_one and create

**URL:** <https://www.ruby-forum.com/t/has-one-and-create/118799>\
**Category:** Rails\
**Created:** [October 31, 2007, 1:23am UTC](https://www.ruby-forum.com/t/has-one-and-create/118799 "2007-10-31T01:23:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nigel.bris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e95f7d/32.png) [@nigel.bris](https://www.ruby-forum.com/u/nigel.bris)\
**Post date:** [October 31, 2007, 1:23am UTC](https://www.ruby-forum.com/t/has-one-and-create/118799/1 "2007-10-31T01:23:08Z")

</div>

Hi,

I am wondering why this does not work?

Email.find(1).the\_file.create

Email model  
has\_one :the\_file

Email.find(1).the\_file always returns nil (until there is an  
association) and you cannot do a create… Any suggestions?

---

<div class="post-metadata">

**Author:** ![nigel.bris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e95f7d/32.png) [@nigel.bris](https://www.ruby-forum.com/u/nigel.bris)\
**Post date:** [October 31, 2007, 2:51pm UTC](https://www.ruby-forum.com/t/has-one-and-create/118799/2 "2007-10-31T14:51:46Z")

</div>

On 10/30/07, nigel.bris [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi,
> 
> I am wondering why this does not work?
> 
> Email.find(1).the\_file.create

It doesn’t work because that’s now how you do it. has\_one works  
differently from has\_many.

> Email model  
> has\_one :the\_file
> 
> Email.find(1).the\_file always returns nil (until there is an  
> association) and you cannot do a create… Any suggestions?

Per the docs:

Email.find(1).create\_the\_file(attrs)

see:

> **[ActiveRecord::Associations::ClassMethods](https://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#M000656)**
>
> Associations are a set of macro-like class methods for tying objects together through foreign keys.

HTH
