Your SlideShare is downloading. ×
  • Like
Rails: has_many vs has_one
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Rails: has_many vs has_one

  • 2,075 views
Published

 

Published in Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
2,075
On SlideShare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
6
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide









Transcript

  • 1. has_many vs has_one 2010/10/02 Shouichi KAMIYA
  • 2. Given class App ActiveRecord::Base has_many :servers end class Server ActiveRecord::Base belongs_to :app end
  • 3. Then irb> app = App.new irb > app.servers = [Server.new] irb > app.servers #=> [#<Server:0x101141d68>]
  • 4. Looking good.
  • 5. Given class App ActiveRecord::Base has_one :server end class Server ActiveRecord::Base belongs_to :app end
  • 6. Then irb> app = App.new irb > app.server = Server.new irb > app.server #=> nil
  • 7. What!?
  • 8. The correct way irb> app = App.new irb > app.set_server_target = Server.new irb > app.server #=> #<Server:0x101141d68>
  • 9. WTF... Thanks!