# Where can i find a good tutorial for has\_one and belongs\_to?

**URL:** <https://www.ruby-forum.com/t/where-can-i-find-a-good-tutorial-for-has-one-and-belongs-to/95201>\
**Category:** Rails\
**Created:** [May 24, 2006, 5:03pm UTC](https://www.ruby-forum.com/t/where-can-i-find-a-good-tutorial-for-has-one-and-belongs-to/95201 "2006-05-24T17:03:25Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![chenge](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a9a28c/32.png) [@chenge](https://www.ruby-forum.com/u/chenge)\
**Post date:** [May 24, 2006, 5:03pm UTC](https://www.ruby-forum.com/t/where-can-i-find-a-good-tutorial-for-has-one-and-belongs-to/95201/1 "2006-05-24T17:03:25Z")

</div>

thanks for helps!

---

<div class="post-metadata">

**Author:** ![chenge](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a9a28c/32.png) [@chenge](https://www.ruby-forum.com/u/chenge)\
**Post date:** [May 24, 2006, 5:27pm UTC](https://www.ruby-forum.com/t/where-can-i-find-a-good-tutorial-for-has-one-and-belongs-to/95201/2 "2006-05-24T17:27:24Z")

</div>

[http://blog.invisible.ch/files/rails-reference-1.1.pdf](http://blog.invisible.ch/files/rails-reference-1.1.pdf)  
chapter 3

---

<div class="post-metadata">

**Author:** ![chenge](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a9a28c/32.png) [@chenge](https://www.ruby-forum.com/u/chenge)\
**Post date:** [May 24, 2006, 6:35pm UTC](https://www.ruby-forum.com/t/where-can-i-find-a-good-tutorial-for-has-one-and-belongs-to/95201/3 "2006-05-24T18:35:40Z")

</div>

thanks.

i want to know if i can test these associations in a standalone rb  
file(without webrick), i tried and it didn’t work.

i use:

require ‘rubygems’  
require\_gem ‘activerecord’

ActiveRecord::Base.establish\_connection(  
:adapter =\> ‘mysql’,  
:socket=\>‘/var/run/mysqld/mysqld.sock’,  
:host =\> ‘localhost’,  
:username =\> ‘root’,  
:password =\> ‘’,  
:database =\> ‘db1’  
)

class Order \< ActiveRecord::Base  
has\_one :Item  
end  
class Item \< ActiveRecord::Base  
belongs\_to :Order  
end

…  
order.item =item  
…

it told me ‘item=’ not defined.

must i test under the support of webrick or script/console?

paolo maldini wrote:

> [http://blog.invisible.ch/files/rails-reference-1.1.pdf](http://blog.invisible.ch/files/rails-reference-1.1.pdf)  
> chapter 3

---

<div class="post-metadata">

**Author:** ![chenge](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a9a28c/32.png) [@chenge](https://www.ruby-forum.com/u/chenge)\
**Post date:** [May 24, 2006, 8:01pm UTC](https://www.ruby-forum.com/t/where-can-i-find-a-good-tutorial-for-has-one-and-belongs-to/95201/4 "2006-05-24T20:01:09Z")

</div>

Hey Chen, I would recommend going through the following at:

\*\*[http://developer.apple.com/tools/rubyonrails.html](http://developer.apple.com/tools/rubyonrails.html)

BTW, it doesn’t cover ‘has\_one’ but it uses the ‘has\_many’.  
In addition to that it covers the following:

- belongs\_to
- migrations

Peace,

-Conrad

---

<div class="post-metadata">

**Author:** ![chenge](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a9a28c/32.png) [@chenge](https://www.ruby-forum.com/u/chenge)\
**Post date:** [May 25, 2006, 2:27pm UTC](https://www.ruby-forum.com/t/where-can-i-find-a-good-tutorial-for-has-one-and-belongs-to/95201/5 "2006-05-25T14:27:29Z")

</div>

On May 24, 2006, at 8:33 PM, chen ge wrote:

> thanks for helps!

> **[Computers - TheTechReviewer.com](https://thetechreviewer.com/computers/)**
>
> A section covering all things computers or anything that you'd plug into one. This includes PC or Mac computers as well as their related peripherals or

Warren

---

<div class="post-metadata">

**Author:** ![chenge](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a9a28c/32.png) [@chenge](https://www.ruby-forum.com/u/chenge)\
**Post date:** [May 27, 2006, 2:05am UTC](https://www.ruby-forum.com/t/where-can-i-find-a-good-tutorial-for-has-one-and-belongs-to/95201/6 "2006-05-27T02:05:43Z")

</div>

chen ge wrote:

> ActiveRecord::Base.establish\_connection(  
> end
> 
> must i test under the support of webrick or script/console?

That’s what script/console is for - it’s extremely useful.

regards

Justin
