# Programatically determine owner class

**URL:** <https://www.ruby-forum.com/t/programatically-determine-owner-class/123469>\
**Category:** Rails\
**Created:** [December 18, 2007, 1:34am UTC](https://www.ruby-forum.com/t/programatically-determine-owner-class/123469 "2007-12-18T01:34:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dangermoose](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e79b87/32.png) [@dangermoose](https://www.ruby-forum.com/u/dangermoose)\
**Post date:** [December 18, 2007, 1:34am UTC](https://www.ruby-forum.com/t/programatically-determine-owner-class/123469/1 "2007-12-18T01:34:19Z")

</div>

If say I have this class:

class MyClass  
self.belongs\_to(:user)  
end

Is there a way to programatically determine who MyClass belongs to?

---

<div class="post-metadata">

**Author:** ![dangermoose](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e79b87/32.png) [@dangermoose](https://www.ruby-forum.com/u/dangermoose)\
**Post date:** [December 18, 2007, 1:47am UTC](https://www.ruby-forum.com/t/programatically-determine-owner-class/123469/2 "2007-12-18T01:47:12Z")

</div>

look at ActiveRecord::Reflection::ClassMethods, specifically the  
reflect\_on\_all\_associations() and reflections() methods

Adam

---

<div class="post-metadata">

**Author:** ![dangermoose](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e79b87/32.png) [@dangermoose](https://www.ruby-forum.com/u/dangermoose)\
**Post date:** [December 18, 2007, 1:47am UTC](https://www.ruby-forum.com/t/programatically-determine-owner-class/123469/3 "2007-12-18T01:47:12Z")

</div>

oops, forgot to post the link

> **[ActiveRecord::Reflection::ClassMethods](https://api.rubyonrails.org/classes/ActiveRecord/Reflection/ClassMethods.html)**
>
> Reflection enables the ability to examine the associations and aggregations of Active Record classes and objects.
