Forum: Ruby on Rails where can i find a good tutorial for has_one and belongs_to?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Chen G. (Guest)
on 2006-05-24 19:03
thanks for helps!
Paolo M. (Guest)
on 2006-05-24 19:27
Chen G. (Guest)
on 2006-05-24 20:35

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'

   :adapter => 'mysql',
   :host => 'localhost',
   :username => 'root',
   :password => '',
   :database => 'db1'

 class Order < ActiveRecord::Base
	has_one :Item
 class Item < ActiveRecord::Base
	belongs_to :Order

order.item =item

it told me 'item=' not defined.

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

paolo maldini wrote:
> chapter 3
Conrad T. (Guest)
on 2006-05-24 22:01
(Received via mailing list)
Hey Chen, I would recommend going through the following at:


BTW, it doesn't cover 'has_one' but it uses the 'has_many'.
In addition to that it covers the following:

- belongs_to
- migrations


Warren N. (Guest)
on 2006-05-25 16:27
(Received via mailing list)
On May 24, 2006, at 8:33 PM, chen ge wrote:

> thanks for helps!

Justin F. (Guest)
on 2006-05-27 04:05
(Received via mailing list)
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.


This topic is locked and can not be replied to.