magic_hat wrote:
> The STI inheiritance has some weird loading behavior. Writers are not
> found with RegisteredUser.find until after they've been loaded with
> Writer.find:
>
>> RegisteredUser.find_by_name('John Doe')
> => nil
>>> Writer.find_by_name('John Doe')
> => #<Writer id: 1, name: "John Doe">
>>> RegisteredUser.find_by_name('John Doe')
> => #<Writer id: 1, name: "John Doe">
>
> Any idea what that's all about?
Yes, STI subclasses aren't added to find conditions
until they're loaded.
One way to force loading of subclasses is to call
require_dependency at the bottom of model files.
e.g. require_dependency 'writer'.
Another way is to name each leaf STI class in
environment.rb, which forces loading of all classes
up the tree.
You may have to use method 2 for production mode
and method 1 for other modes.
There's also this plugin, which I haven't yet tried:
http://agilewebdevelopment.com/plugins/has_types
--
Rails Wheels - Find Plugins, List & Sell Plugins - http://railswheels.com
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---