Hi all, How would one obtain the database table name if given a column name? Does ActiveRecord know how to do that? For example if there is a model that "belongs_to :myobject_id", is there a way to get the table name from "myobject_id" ? Thank you, Vic -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Kevin
2007-Mar-20 09:05 UTC
Re: Obtaining table information from "belongs_to"? (reflection?)
On Mar 19, 7:43 am, Vic <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> How would one obtain the database table name if given a column name? > Does ActiveRecord know how to do that?>From http://railsmanual.org/module/ActiveRecord::Reflection::ClassMethods/reflect_on_association/1.1.2""" Returns the AssociationReflection object for the named aggregation (use the symbol). Example: Account.reflect_on_association(:owner) # returns the owner AssociationReflection Invoice.reflect_on_association(:line_items).macro # returns :has_many """ Then you should be able to call table_name() on the AssociationReflection: Account.reflect_on_association(:owner).table_name # returns ''account'' Kevin --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---