#1241 ✓resolved
sundbp

STI descendants get destroyed in rails console

Reported by sundbp | April 12th, 2010 @ 05:34 AM | in 1.0.2

When #reload! in railties/lib/rails/console/app.rb is called any STI relationships in DM get destroyed.

I've attached an almost empty rails app to demostrate. It has 3 models - Parent, ChildA and ChildB where the two children inherits from Parent.

If you do:
* bundle install * ./script/rails c * Parent.descendants.each {|x| p x}

you will see the output being only "Parent". Comment out the reload! call at the end of railties/lib/rails/console/app.rb and run it again and you'll see the expected output that includes also ChildA and ChildB.

I haven't figured out what the best way of doing this is. It has to do with the fact that calling require on the models more than once breaks descendants. It'd seem that one could either:
1. make it possible to require models multiple times without breaking descendants
2. introduce some sort of callback for properly reloading DM models in a controlled fashion. I think the current reload! will just undefine some stuff and then rely on the auto-require feature of ActiveSupport to load the models again.

It seems 1 would be preferable to me but I haven't figured out how to make it happen..

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Tags

Referenced by

Pages