# ActiveRecord: Can't store a class derived from AR::Base

**URL:** <https://www.ruby-forum.com/t/activerecord-cant-store-a-class-derived-from-ar-base/157400>\
**Category:** Rails\
**Created:** [January 10, 2009, 4:30pm UTC](https://www.ruby-forum.com/t/activerecord-cant-store-a-class-derived-from-ar-base/157400 "2009-01-10T16:30:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daniel\_VSSSSlkerts](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/d26b3c/32.png) [@Daniel\_VSSSSlkerts](https://www.ruby-forum.com/u/Daniel_VSSSSlkerts)\
**Post date:** [January 10, 2009, 4:30pm UTC](https://www.ruby-forum.com/t/activerecord-cant-store-a-class-derived-from-ar-base/157400/1 "2009-01-10T16:30:27Z")

</div>

Hi,

try to use ActiveRecord for my little standalone application, without  
the rails environment. Here is my first try

8\<--------------------------------------------------

# Main

if **FILE** == $0 then

ActiveRecord::Base.establish\_connection(  
:adapter =\> ‘mysql’,  
:host =\> @config[:sql][:hostname],  
:database =\> @config[:sql][:database],  
:username =\> @config[:sql][:username],  
:password =\> @config[:sql][:password]  
)

puts 'Erzeuge ein paar Knoten und speicher diese in der DB: ’

80.times do |i|  
aNode = Node.new(“node\_#{i}”,1)  
print ‘.’  
aNode.save!  
end

end

8\<--------------------------------------------------

@config is well initialized, the ActiveRecord connects to my DB as  
you’ll expected. But the call aNode.save! fails with this error:

Erzeuge ein paar Knoten und speicher diese in der DB:  
.c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active\_record/transactions.rb:164:in  
`rollback_active_record_state!': undefined method`delete’ for  
nil:NilClass (NoMethodError)  
from  
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active\_record/transactions.rb:150:in  
`save!' from main.rb:35 from main.rb:32:in`times’  
from main.rb:32

Mmm, but I have looked in transactions.rb at line 150 and 164, looks  
fine for me. My AR gems are

D:\ramantics\>gem list --local

\*\*\* LOCAL GEMS \*\*\*

actionmailer (2.2.2)  
actionpack (2.2.2)  
activerecord (2.2.2)  
activeresource (2.2.2)  
activesupport (2.2.2)  
fxri (0.3.7, 0.3.6)  
fxruby (1.6.17, 1.6.6)  
hpricot (0.6.164, 0.4)  
log4r (1.0.5)  
mysql (2.7.3)  
ptools (1.1.6)  
rails (2.2.2)  
rake (0.8.3, 0.7.2)  
rubygems-update (1.3.1)  
sources (0.0.1)  
test-unit (2.0.2)  
win32-api (1.2.2)  
win32-clipboard (0.4.4, 0.4.1)  
win32-dir (0.3.2, 0.3.1)  
win32-eventlog (0.5.0, 0.4.3)  
win32-file (0.6.0, 0.5.3)  
win32-file-stat (1.3.2, 1.2.3)  
win32-process (0.6.0, 0.5.1)  
win32-sapi (0.1.4, 0.1.3)  
win32-sound (0.4.1, 0.4.0)  
windows-api (0.2.4)  
windows-pr (0.9.8, 0.6.2)

Has anyone an idea where I made the mistake? Thanks a lot.

g,

Daniel

---

<div class="post-metadata">

**Author:** ![Daniel\_VSSSSlkerts](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/d26b3c/32.png) [@Daniel\_VSSSSlkerts](https://www.ruby-forum.com/u/Daniel_VSSSSlkerts)\
**Post date:** [January 10, 2009, 8:43pm UTC](https://www.ruby-forum.com/t/activerecord-cant-store-a-class-derived-from-ar-base/157400/2 "2009-01-10T20:43:06Z")

</div>

On Jan 9, 9:26 pm, Daniel Völkerts [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Has anyone an idea where I made the mistake? Thanks a lot.

Have you override initialize in you Node class ?

Fred

---

<div class="post-metadata">

**Author:** ![Daniel\_VSSSSlkerts](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/d26b3c/32.png) [@Daniel\_VSSSSlkerts](https://www.ruby-forum.com/u/Daniel_VSSSSlkerts)\
**Post date:** [January 11, 2009, 12:33pm UTC](https://www.ruby-forum.com/t/activerecord-cant-store-a-class-derived-from-ar-base/157400/3 "2009-01-11T12:33:51Z")

</div>

Frederick C. schrieb:

> Have you override initialize in you Node class ?

Hi Fred,

aaah yes. I already found the problem. As you mentioned, I overwrote  
initialize in my Node class which inherits AR::Base.

Damn I didn’t know that this isn’t allowed ☹ Fixed failures lead to  
better code _g_

Thanks for your response.

Daniel

–  
“Das ich erkenne, was die Welt im Innersten zusammenhält” (Faust I)

---

<div class="post-metadata">

**Author:** ![Daniel\_VSSSSlkerts](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/d26b3c/32.png) [@Daniel\_VSSSSlkerts](https://www.ruby-forum.com/u/Daniel_VSSSSlkerts)\
**Post date:** [January 11, 2009, 3:21pm UTC](https://www.ruby-forum.com/t/activerecord-cant-store-a-class-derived-from-ar-base/157400/4 "2009-01-11T15:21:54Z")

</div>

On 11 Jan 2009, at 11:33, Daniel Völkerts wrote:

> Damn I didn’t know that this isn’t allowed ☹ Fixed failures lead to  
> better code _g_

You can override initialize, but you just need to ensure you call the  
superclass implementation properly.

Fred

---

<div class="post-metadata">

**Author:** ![Daniel\_VSSSSlkerts](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/d26b3c/32.png) [@Daniel\_VSSSSlkerts](https://www.ruby-forum.com/u/Daniel_VSSSSlkerts)\
**Post date:** [January 11, 2009, 9:06pm UTC](https://www.ruby-forum.com/t/activerecord-cant-store-a-class-derived-from-ar-base/157400/5 "2009-01-11T21:06:27Z")

</div>

Frederick C. schrieb:

> You can override initialize, but you just need to ensure you call the  
> superclass implementation properly.

Oh, thanks for this additional information, I see I’ve to read the docs  
,)

g,

Daniel

–  
“Das ich erkenne, was die Welt im Innersten zusammenhält” (Faust I)
