• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Rails: has_many vs has_one
 

Rails: has_many vs has_one

on

  • 2,401 views

 

Statistics

Views

Total Views
2,401
Views on SlideShare
2,401
Embed Views
0

Actions

Likes
0
Downloads
5
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

CC Attribution-ShareAlike LicenseCC Attribution-ShareAlike License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />

Rails: has_many vs has_one Rails: has_many vs has_one Presentation Transcript

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