Forum: Ruby on Rails Doesn't "find" call initialize?

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.
r00by n00by (Guest)
on 2006-01-04 17:05
class Item < ActiveRecord::Base

   def initialize(*args)
      super
      @x = 5

   end

   def print_x
      puts @x
   end
end


item_new = Item.new
item_new.print_x   # output: 5

item_find = Item.find(1) # this record is in the database
item_find.print_x  # output: nil


I thought the output would be 5 in both cases, since Item.find returns a
new object of Item and so Item.initialize would be called
This topic is locked and can not be replied to.