allen
2007-Apr-09 02:33 UTC
Is there a utility tool to check the convention between DB table and AR model?
Say that I could just enter the AR model''s name, and it will output the DB table''s name according to rails'' default convention. Thanks. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Jeremy McAnally
2007-Apr-09 03:27 UTC
Re: Is there a utility tool to check the convention between DB table and AR model?
The tableize method will return the table-convention-version of a string; this means you could do something like the following: def table_name(model) model.to_s.tableize # stringify a class name and tableize it end table_name(User)>> userstable_name(Session)>> sessionstable_name(TeamMember)>> team_members--Jeremy On 4/8/07, allen <allenmacyoung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Say that I could just enter the AR model''s name, and it will output > the DB table''s name according to rails'' default convention. Thanks. > > > > >-- http://www.jeremymcanally.com/ My free Ruby e-book: http://www.humblelittlerubybook.com/book/ My blogs: http://www.mrneighborly.com/ http://www.rubyinpractice.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 -~----------~----~----~----~------~----~------~--~---
allen
2007-Apr-09 03:51 UTC
Re: Is there a utility tool to check the convention between DB table and AR model?
Thanks a lot! On Apr 9, 11:27 am, "Jeremy McAnally" <jeremymcana...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> The tableize method will return the table-convention-version of a > string; this means you could do something like the following: > > def table_name(model) > model.to_s.tableize # stringify a class name and tableize it > end > > table_name(User)>> users > table_name(Session) > >> sessions > > table_name(TeamMember) > > >> team_members > > --Jeremy > > On 4/8/07, allen <allenmacyo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Say that I could just enter the AR model''s name, and it will output > > the DB table''s name according to rails'' default convention. Thanks. > > --http://www.jeremymcanally.com/ > > My free Ruby e-book:http://www.humblelittlerubybook.com/book/ > > My blogs:http://www.mrneighborly.com/http://www.rubyinpractice.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 -~----------~----~----~----~------~----~------~--~---