ChongQing Xiao
2004-Nov-30 17:25 UTC
RE: question about rails regarding handling more thanonetable in one view
Hi, Jarkko: Thanks for the answer. Now I have a lot to read and try. Rails really rocks. chong ________________________________ From: rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Jarkko Laine Sent: Tuesday, November 30, 2004 11:20 AM To: rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: Re: [Rails] question about rails regarding handling more thanonetable in one view Hi Chong, On 30.11.2004, at 19:07, ChongQing Xiao wrote: 1. Since I have a third table ProvWorkAtDept, do I need to specify this table somewhere when I define Provider or Dept? From http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethod s.html#M000121: has_and_belongs_to_many Associates two classes via an intermediate join table. Unless the join table is explicitly specified as an option, it is guessed using the lexical order of the class names. So a join between Developer and Project will give the default join table name of "developers_projects" because "D" outranks "P". 2. If the provider view has both the provider name and several depts the provider works on, how that data will be handled by the Provider model or controller, You will have a method called Provider#depts which will return an array (I think) consisting of Dept objects. Plus many other nifty methods that you can find from that same address above. Do I need write code in Provider model (or the controller) to call Provider#Dept<<Dept (or Provider#Dept.Build, Create) to save the relation to ProvWorkAtDept table Or rails will handle it automatically? Provider#depts<< @deptobject will do what is needed. You don''t have to write any additional code. It will be great if you give me some explanation between provider view, model and the controller regarding how the depts will be filed. This all has been part of ActiveRecord (=model). You will of course call those functions (like Provider#depts<< @deptobject) in your controllers. Hope this made things a bit clearer. //jarkko -- Jarkko Laine http://jlaine.net _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails