Hi, This does not seem to be covered anywhere. Since base class extends ActiveRecord with a table that has fields for all heirs, would that mean that any heir class can access any of those attributes, including ones that belong to other heirs? Or I am missing something? -- Posted via http://www.ruby-forum.com/.
David Heinemeier Hansson
2006-Mar-22 17:44 UTC
[Rails] STI and ActiveRecord attributes unprotected
> This does not seem to be covered anywhere. Since base class extends > ActiveRecord with a table that has fields for all heirs, would that mean > that any heir class can access any of those attributes, including ones > that belong to other heirs? > > Or I am missing something?You''re correct. All classes in an STI setup has access to all attributes. Usually the answer is: It Just Doesn''t Matter. But if it does to you, you can always use attr_protected or overwrite the other attributes with accessors that throws an exception. Whatever floats your boat ;) -- David Heinemeier Hansson http://www.loudthinking.com -- Broadcasting Brain http://www.basecamphq.com -- Online project management http://www.backpackit.com -- Personal information manager http://www.rubyonrails.com -- Web-application framework
Sergei Serdyuk
2006-Mar-23 02:29 UTC
[Rails] Re: STI and ActiveRecord attributes unprotected
David, I have a lot trust in your decisions and opinions, but what about things that iterate over attribute collections like scaffolds for example? Neither solution will work correctly with them. I am not saying this is the end of the world. Just an observation.> Usually the answer is: It Just Doesn''t Matter. But if it > does to you, you can always use attr_protected or overwrite the other > attributes with accessors that throws an exception. Whatever floats > your boat ;)-- Posted via http://www.ruby-forum.com/.
Wilson Bilkovich
2006-Mar-23 02:43 UTC
[Rails] Re: STI and ActiveRecord attributes unprotected
On 3/22/06, Sergei Serdyuk <sserdyuk@hotmail.com> wrote:> David, I have a lot trust in your decisions and opinions, but what about > things that iterate over attribute collections like scaffolds for > example? Neither solution will work correctly with them. I am not saying > this is the end of the world. Just an observation. > > > Usually the answer is: It Just Doesn''t Matter. But if it > > does to you, you can always use attr_protected or overwrite the other > > attributes with accessors that throws an exception. Whatever floats > > your boat ;) >If you can think of a way for ActiveRecord to know which attributes belong to which subclass without having to specify them "by hand" in the model file, I''d be happy to work on a patch. I haven''t been able to come up with anything solid myself; this is just a side-effect of the column auto-discovery technique AR uses, in my opinion.