[ I''m still hoping for some help with this, folks... -r ] As part of the Arti (http://mephisto-ar.cfcl.com) effort, I''m looking into creating a database to store information on entities and relationships found in Ruby and Rails, as: Method M1 is defined for Class C1 in File F1. Method M1 of Class C1 is used by Method M2 in File F2. Disregarding (for the moment) questions of Ruby ontology, let''s look at how this information might be encoded in AR. I gather that AR wants me to name join files by the ordered names of the tables being joined. So, if I have tables named "classes", "files", and "methods", I would create a join file named "classes_files_methods". I have two relationships that join the same set of tables, so I need a way to tell them apart. I can do so by means of a "type" column, with values such as "defines" and "uses". However, I''m not at all sure that AR supports multi-table joins. In fact, my inquiries indicate that it does not. I could use model code to work around this problem, but I''d like to keep things as simple as possible. Am I missing some obvious answer? Can someone suggest some code and/or documentation that addresses this issue? -r -- http://www.cfcl.com/rdm Rich Morin http://www.cfcl.com/rdm/resume rdm-go8te9J4rpw@public.gmane.org http://www.cfcl.com/rdm/weblog +1 650-873-7841 Technical editing and writing, programming, and web development --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Ball, Donald A Jr \(Library\)
2007-Apr-09 17:48 UTC
Re: multi-way join files with types? (resend)
> -----Original Message----- > From: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > [mailto:rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org] On Behalf Of Rich Morin > Sent: Monday, April 09, 2007 10:12 AM > To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > Subject: [Rails] multi-way join files with types? (resend) > > > [ I''m still hoping for some help with this, folks... -r ] > > > As part of the Arti (http://mephisto-ar.cfcl.com) effort, I''m > looking into creating a database to store information on > entities and relationships found in Ruby and Rails, as: > > Method M1 is defined for Class C1 in File F1.For this, I''d make each method belongs_to a file, each file has_many methods, and each class has_many methods through files.> Method M1 of Class C1 is used by Method M2 in File F2.Here I''d think you''d want a new table, e.g. MethodInvokations, with a user_method_id, a used_method_id, and a file_id. As far as I know, ActiveRecord only supports join tables with two columns, so this would need to be a new model object, MethodInvokation, but that''s no big deal, the only complication would seem to be that the MethodInvokation object belongs to two different Method objects in two different ways. But you might do it like: class MethodInvokation < ActiveRecord::Base belongs_to :user_method, :class_name=>''Method'', :foreign_key=>''user_method_id'' belongs_to :used_method, :class_name=>''Method'', :foreign_key=>''used_method_id'' belongs_to :file end and in the method class, maybe something like: class Method < ActiveRecord::Base has_many :invokers, :class_name=>''MethodInvokation'', :foreign_key=>''used_method_id'' has_many :invokations, :class_name=>''MethodInvokations'', :foreign_key=>''user_method_id'' end I''m no ActiveRecord expert, so take with a grain of salt, but this is how I''d start to model it. - donald --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---