Forum: Ruby on Rails ActiveRecord::Reflection active_record read-only method

1d4a45a695b48edc70359ca6d015e2f4?d=identicon&s=25 John Merlino (johnmerlino)
on 2012-07-31 03:11
(Received via mailing list)
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(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

Well, that's not too informative...

thanks for response
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2012-07-31 11:43
(Received via mailing list)
On Tuesday, July 31, 2012 2:09:41 AM UTC+1, John Merlino wrote:
> What's your question (and what the relationship with  your subject line?) ?

1d4a45a695b48edc70359ca6d015e2f4?d=identicon&s=25 John Merlino (johnmerlino)
on 2012-08-01 02:21
(Received via mailing list)
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 Cheung <>
Fef890509958b45df342b53e839920c9?d=identicon&s=25 Ace S. (ace_s)
on 2012-08-01 13:55
(Received via mailing list)
I think, #reflect_on_association is a class method. So it tells you if
class has some association and the stuff related to that.

Account.reflect_on_association(:users) will give you some information
how the attribute :users is associated with the model Account. Probably,
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.

Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.