# Single table inheritance: declare non-shared attributes

**URL:** <https://www.ruby-forum.com/t/single-table-inheritance-declare-non-shared-attributes/136163>\
**Category:** Rails\
**Created:** [April 29, 2008, 3:27pm UTC](https://www.ruby-forum.com/t/single-table-inheritance-declare-non-shared-attributes/136163 "2008-04-29T15:27:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![song](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ecd19e/32.png) [@song](https://www.ruby-forum.com/u/song)\
**Post date:** [April 29, 2008, 3:27pm UTC](https://www.ruby-forum.com/t/single-table-inheritance-declare-non-shared-attributes/136163/1 "2008-04-29T15:27:14Z")

</div>

Hi!  
I have a Model Foo and two subclasses Bar1 and Bar2. Bar1 have some  
attributes which shouldn’t be accessible in Bar2 (because they aren’t  
needed), what is the best practice to declare such attributes as  
non-shared?  
Thx!

---

<div class="post-metadata">

**Author:** ![song](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ecd19e/32.png) [@song](https://www.ruby-forum.com/u/song)\
**Post date:** [April 29, 2008, 7:09pm UTC](https://www.ruby-forum.com/t/single-table-inheritance-declare-non-shared-attributes/136163/2 "2008-04-29T19:09:33Z")

</div>

declare them only in Bar1?

On Tue, Apr 29, 2008 at 7:27 AM, Kai S.

---

<div class="post-metadata">

**Author:** ![song](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ecd19e/32.png) [@song](https://www.ruby-forum.com/u/song)\
**Post date:** [April 30, 2008, 1:31pm UTC](https://www.ruby-forum.com/t/single-table-inheritance-declare-non-shared-attributes/136163/3 "2008-04-30T13:31:47Z")

</div>

These attributes have columns in the underlying table, and ActiveRecord  
make them accessible by default…

---

<div class="post-metadata">

**Author:** ![song](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ecd19e/32.png) [@song](https://www.ruby-forum.com/u/song)\
**Post date:** [April 30, 2008, 4:49pm UTC](https://www.ruby-forum.com/t/single-table-inheritance-declare-non-shared-attributes/136163/4 "2008-04-30T16:49:47Z")

</div>

maybe redefine the ‘hidden’ fields in the model they’re not supposed  
to be used in. A la  
class Foo \< Item  
def attribut\_used\_by\_bar  
raise ‘you cant read that!’  
end  
end

On Wed, Apr 30, 2008 at 5:31 AM, Kai S.
