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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
05faf3e7b9ac65d5090ea404c27f8f26?d=identicon&s=25 Chen Ge (chenge)
on 2006-05-24 17:03
thanks for helps!
7984f85eb1ace0ff40f2433ce26a95a1?d=identicon&s=25 Paolo Maldini (pm3)
on 2006-05-24 17:27
05faf3e7b9ac65d5090ea404c27f8f26?d=identicon&s=25 Chen Ge (chenge)
on 2006-05-24 18:35
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
> chapter 3
40db9e75b3f5899258e3bdc0c9210154?d=identicon&s=25 Conrad Taylor (Guest)
on 2006-05-24 20:01
(Received via mailing list)
Hey Chen, I would recommend going through the following at:

**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
711eb56e970b483e2c9d929bd036a89e?d=identicon&s=25 Warren Noronha (Guest)
on 2006-05-25 14:27
(Received via mailing list)
On May 24, 2006, at 8:33 PM, chen ge wrote:

> thanks for helps!

http://www.hyperionreactor.net/node/60

Warren
Eea7ad39737b0dbf3de38874e0a6c7d8?d=identicon&s=25 Justin Forder (Guest)
on 2006-05-27 02: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.

regards

   Justin
This topic is locked and can not be replied to.