
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
-
Martin Gamsjaeger (snusnu) April 15th, 2010 @ 11:27 AM
- State changed from new to confirmed
- Assigned user set to Martin Gamsjaeger (snusnu)
- Milestone set to 1.0.0
-
Martin Gamsjaeger (snusnu) June 3rd, 2010 @ 08:38 AM
- Milestone cleared.
- Tag set to dm-rails
Indeed the call to #reload! in railties/console/app is evil. IIRC, I even heard someone say that ActiveRecord has problems with STI in the console too (I might be wrong on that one tho). In any case, I don't think I can solve this before 1.0, and tbh, I don't think that's a blocker either!
I'm removing the Milestone for now, but we will definitely not forget about this ticket!
-
Martin Gamsjaeger (snusnu) June 24th, 2010 @ 06:39 PM
- Milestone set to 1.0.2
Patrik, can you confirm that http://github.com/rails/rails/commit/6682cce0386811ffe3e6d31fc025ed... fixes this issue?
-
sundbp June 25th, 2010 @ 04:06 AM
This was the patch I had in my local branch so it should be good. However, I haven't kept up with changes lately so would need to update DM and rails to head to check out for sure. I'll try to do so and get back to you.
-
Martin Gamsjaeger (snusnu) June 27th, 2010 @ 10:36 AM
- State changed from confirmed to resolved
- Milestone order changed from 0 to 0
Ok, I tried that out actually at the time, and confirmed that commenting out
reload
worked. Marking this resolved for now. We can always reopen it if it's still an issue. -
sundbp June 27th, 2010 @ 11:48 AM
Makes sense. I haven't updated to head etc - ridiculously good weather here in London this weekend so haven't touched a computer :)
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.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
People watching this ticket
Tags
Referenced by
-
1238 Discriminator issue I could be related to this ticket:: http://datamapper.li...