# ActiveRecord::Reflection active\_record read-only method

**URL:** <https://www.ruby-forum.com/t/activerecord-reflection-active-record-read-only-method/221785>\
**Category:** Rails\
**Created:** [July 31, 2012, 3:11am UTC](https://www.ruby-forum.com/t/activerecord-reflection-active-record-read-only-method/221785 "2012-07-31T03:11:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [July 31, 2012, 3:11am UTC](https://www.ruby-forum.com/t/activerecord-reflection-active-record-read-only-method/221785/1 "2012-07-31T03:11:24Z")

</div>

I was horsing around with the reflect\_on\_assocation class method of  
ActiveRecord Reflection, which returns an instance of  
AssociationReflection. One of its methods is called active\_record. I  
run it in console:

Account.reflect\_on\_association(:users).active\_record  
=\> Account(id: integer, name: string, created\_at: datetime,  
updated\_at: datetime, ancestry: string, street\_address: string, city:  
string, postal\_code: string, state: string, country: string,  
street\_address2: string, account\_type\_id: integer, client\_logo:  
string, subdomain: string, email: string, phone: string)

What it returns is not the Account object.

According to documentation, it “Returns the value of attribute  
active\_record”.

[http://rubydoc.info/docs/rails/3.0.0/ActiveRecord/Reflection/MacroReflection#active\_record-instance\_method](http://rubydoc.info/docs/rails/3.0.0/ActiveRecord/Reflection/MacroReflection#active_record-instance_method)

Well, that’s not too informative…

thanks for response

---

<div class="post-metadata">

**Author:** ![jmaenpaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de053/32.png) [@jmaenpaa](https://www.ruby-forum.com/u/jmaenpaa)\
**Post date:** [July 31, 2012, 11:43am UTC](https://www.ruby-forum.com/t/activerecord-reflection-active-record-read-only-method/221785/2 "2012-07-31T11:43:11Z")

</div>

On Tuesday, July 31, 2012 2:09:41 AM UTC+1, John M. wrote:

> What’s your question (and what the relationship with your subject line?) ?

Fred

---

<div class="post-metadata">

**Author:** ![jmaenpaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de053/32.png) [@jmaenpaa](https://www.ruby-forum.com/u/jmaenpaa)\
**Post date:** [August 1, 2012, 2:21am UTC](https://www.ruby-forum.com/t/activerecord-reflection-active-record-read-only-method/221785/3 "2012-08-01T02:21:33Z")

</div>

I’m saying that active\_record called on AssociationReflection seems to  
just return the class object itself. For example:

Account.reflect\_on\_association(:users).active\_record # =\> Account

What’s the point of that? Can’t you just do Account.class?

On Jul 31, 5:42am, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![jmaenpaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de053/32.png) [@jmaenpaa](https://www.ruby-forum.com/u/jmaenpaa)\
**Post date:** [August 1, 2012, 1:55pm UTC](https://www.ruby-forum.com/t/activerecord-reflection-active-record-read-only-method/221785/4 "2012-08-01T13:55:13Z")

</div>

I think, #reflect\_on\_association is a class method. So it tells you if  
the  
class has some association and the stuff related to that.

Account.reflect\_on\_association(:users) will give you some information  
about  
how the attribute :users is associated with the model Account. Probably,  
a  
has\_many association, I guess.

Now, in most cases, it goes like this:

Account.reflect\_on\_association(:users).active\_record =\> User

But in your case, the model Account seems to be associated with itself  
through :users. It would be really helpful if you post your models here.

So, to answer your question: Can’t you just do Account.class?  
Well, in this special case you could, but in most other cases, not.

Hope this helps.

Ace
