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.

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 M.
http://www.cfcl.com/rdm/resume [email protected]
http://www.cfcl.com/rdm/weblog +1 650-873-7841

Technical editing and writing, programming, and web development

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