Where can i find a good tutorial for has_one and belongs_to?


#1

thanks for helps!


#2

http://blog.invisible.ch/files/rails-reference-1.1.pdf
chapter 3


#3

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


#4

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


#5

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

thanks for helps!

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

Warren


#6

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