This project is archived and is in readonly mode.
Namespaced models and STI
Reported by Rodrigo Kochenburger | May 5th, 2008 @ 03:41 PM | in 2.1.1
When using namespaced models and STI, ActiveRecord stores the demodulized name of the class. This work if all the class in the STI hierarchy are in the same namespace but will break otherwise.
Example:
class CollectionItem < ActiveRecord::Base; end
class ComicCollection::Item < CollectionItem; end
item = ComicCollection::Item.new
item.type # => 'Item'
item2 = CollectionItem.find(item.id) # raise an error because can't find class Item
This patch add an option that when enable (it is by default) will store the full class name.
Comments and changes to this ticket
-
Pratik May 11th, 2008 @ 10:45 PM
- State changed from new to incomplete
Why the need to add new tables for tests ? It should be possible to use existing tables.
Rest looks good.
Thanks!
-
Rick May 13th, 2008 @ 09:51 PM
- Milestone set to 2.1.1
- Assigned user set to Rick
I really want this in 2.1. Though, the default should be off to keep the existing behavior, and on for Rails 3.0 and forward.
I also agree that the new tables for tests aren't necessary.
-
Rick May 13th, 2008 @ 09:55 PM
Also, I'm going to remove the choice since it shouldn't break for anyone. Anyone using STI without namespaced models will be unaffected, and this bug is basically preventing anyone from using STI with namespaced models.
-
Rick May 13th, 2008 @ 11:23 PM
- State changed from incomplete to open
-
Repository May 13th, 2008 @ 11:23 PM
(from [bca8751e40a5594c4de2ca58e089b8d98e44632b]) Add ActiveRecord option to store the full class name on STI's type column, allowing one to have STI subclasses in different namespaces [#114]
Signed-off-by: rick
-
Jonathan Viney May 14th, 2008 @ 03:13 AM
HasManyThroughAssociation#build_sti_condition needs to be addressed as well.
-
Rodrigo Kochenburger May 14th, 2008 @ 01:18 AM
That's great. Thanks Rick.
About having extra table, sorry about that. I did that to avoid breaking other things, my bad.
-
Rick May 14th, 2008 @ 03:14 AM
No worries.
Just FYI there are three issues remaining:
- HasManyThroughAssociation#build_sti_condition, as Jonathan mentioned above.
- ActiveRecord::Base#type_name_with_module adds the parent name, resulting in an annoying ruby warning.
- You can't create migration-specific STI models because the migration name will be saved to the #type value too. (see the rails core ML post.
-
Repository June 1st, 2008 @ 01:15 AM
- State changed from open to resolved
(from [72483c0d4c1e4ea794919974100acc2f255f6fd2]) Add ActiveRecord::Base.sti_name that checks ActiveRecord::Base#store_full_sti_class? and returns either the full or demodulized name. [rick] [#114 state:resolved]
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Tags
Referenced by
- 1945 Multipart form with empty file_field submits nil Follow to: http://thoughtbot.lighthouseapp....