# Flattening 1:1 models

**URL:** <https://www.ruby-forum.com/t/flattening-1-1-models/187323>\
**Category:** Rails\
**Created:** [April 21, 2010, 5:58pm UTC](https://www.ruby-forum.com/t/flattening-1-1-models/187323 "2010-04-21T17:58:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomuhs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ecb155/32.png) [@tomuhs](https://www.ruby-forum.com/u/tomuhs)\
**Post date:** [April 21, 2010, 5:58pm UTC](https://www.ruby-forum.com/t/flattening-1-1-models/187323/1 "2010-04-21T17:58:56Z")

</div>

Is there a simple way to flatten 1:1 models so that the methods in one  
are accessible from another? This attempt results in a stack depth  
exception for any call to one of the explicitly defined methods:

class User \< ActiveRecord::Base

has\_one :contact

Contact.column\_names.each do |col|  
define\_method col.to\_sym do  
contact.send col.to\_sym  
end  
end

end

I tried doing this with method\_missing and respond\_to? as well, with  
similarly poor results, so I was hoping that someone else has found a  
way to cleanly map attributes in this way.

Thomas

---

<div class="post-metadata">

**Author:** ![tomuhs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ecb155/32.png) [@tomuhs](https://www.ruby-forum.com/u/tomuhs)\
**Post date:** [April 21, 2010, 8:27pm UTC](https://www.ruby-forum.com/t/flattening-1-1-models/187323/2 "2010-04-21T20:27:54Z")

</div>

Thomas A. wrote:

> Is there a simple way to flatten 1:1 models so that the methods in one  
> are accessible from another? This attempt results in a stack depth  
> exception for any call to one of the explicitly defined methods:

If you wanted all the attributes on one model, why the heck did you  
break them apart in the first place?

I suppose you could write accessors to access the Contact attributes  
through User’s association, but the whole design seem completely silly  
to me. Just get rid of Contact and put it’s attributes on User and be  
done with it. Or, just access Contact’s attributes though the  
association, like the system is designed to do.
