John Merlino
2012-Jul-31 01:09 UTC
ActiveRecord::Reflection active_record read-only method
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 Well, that''s not too informative... thanks for response -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Frederick Cheung
2012-Jul-31 09:42 UTC
Re: ActiveRecord::Reflection active_record read-only method
On Tuesday, July 31, 2012 2:09:41 AM UTC+1, John Merlino wrote:> > > 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 > > > Well, that''s not too informative... > > > What''s your question (and what the relationship with your subject line?) ?Fred -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/R9_hujNydvsJ. For more options, visit https://groups.google.com/groups/opt_out.
John Merlino
2012-Aug-01 00:20 UTC
Re: ActiveRecord::Reflection active_record read-only method
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:42 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Tuesday, July 31, 2012 2:09:41 AM UTC+1, John Merlino wrote: > > > 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/MacroRef... > > > Well, that''s not too informative... > > > What''s your question (and what the relationship with your subject line?) ? > > Fred-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Ace Suares
2012-Aug-01 11:53 UTC
Re: ActiveRecord::Reflection active_record read-only method
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 On Monday, July 30, 2012 9:09:41 PM UTC-4, John Merlino wrote:> > 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 > > > Well, that''s not too informative... > > thanks for response > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/YA_XUXDCgM0J. For more options, visit https://groups.google.com/groups/opt_out.