Has_one and create

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?

On 10/30/07, nigel.bris [email protected] 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:

HTH