# Easy way to add properties to a model?

**URL:** <https://www.ruby-forum.com/t/easy-way-to-add-properties-to-a-model/97592>\
**Category:** Rails\
**Created:** [January 26, 2006, 1:46pm UTC](https://www.ruby-forum.com/t/easy-way-to-add-properties-to-a-model/97592 "2006-01-26T13:46:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![fsommers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/bcef8e/32.png) [@fsommers](https://www.ruby-forum.com/u/fsommers)\
**Post date:** [January 26, 2006, 1:46pm UTC](https://www.ruby-forum.com/t/easy-way-to-add-properties-to-a-model/97592/1 "2006-01-26T13:46:35Z")

</div>

Hi,

I have a model (let’s say User) and I would like to add any number of  
user-defined-settings to this Model. I created a UserSetting Model  
with user\_id, key and value. I connected them with has\_many. I know  
how to access these properties from a user but I would like some  
methods like user.hasProperty? / user.getProperty …

I think I know how to write these methods/finders myself but it seems  
like a pretty common problem to me, which means there could be an  
easier way of doing the same. Is there?

bye  
Frank

---

<div class="post-metadata">

**Author:** ![fsommers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/bcef8e/32.png) [@fsommers](https://www.ruby-forum.com/u/fsommers)\
**Post date:** [January 26, 2006, 6:58pm UTC](https://www.ruby-forum.com/t/easy-way-to-add-properties-to-a-model/97592/2 "2006-01-26T18:58:14Z")

</div>

On Jan 26, 2006, at 5:44 AM, Frank S. wrote:

> easier way of doing the same. Is there?

Nothing automatic, but the code seems trivial anyway:

def get\_property(property)  
user\_settings.find\_by\_key(property)  
end  
alias has\_property? get\_property

Duane J.  
(canadaduane)  
[http://blog.inquirylabs.com/](http://blog.inquirylabs.com/)

---

<div class="post-metadata">

**Author:** ![fsommers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/bcef8e/32.png) [@fsommers](https://www.ruby-forum.com/u/fsommers)\
**Post date:** [January 30, 2006, 11:54am UTC](https://www.ruby-forum.com/t/easy-way-to-add-properties-to-a-model/97592/3 "2006-01-30T11:54:25Z")

</div>

On 1/26/06, Duane J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > 
> 
> alias has\_property? get\_property  
> I think you misunderstood me. If I’m not mistaken, you code would  
> return the same property for every user… But these property will be  
> different for every user.

## bye Frank

[http://amazing-development.com](http://amazing-development.com)
