[Nitro] Og inheritance problem in detail..

Emmanuel Piperakis epiperak at softlab.ece.ntua.gr
Tue Oct 11 22:45:24 EDT 2005

So, I decided to split the 2 problems I face in Og to different postings.
Problem 1. Inheritance

class Project
   property :title, String
   property :creation, Date
   has_many   :reports
   has_one    Bgroup 

class ForeignProject < Project
   property :acquisition_date,     Date
   property :placement_date,       Date
   property :sales_commission_per, Fixnum

class DomesticProject < Project
   property :contract_date,     Date
   property :closing_date,      Date
   property :transfer_date,     Date
   property :loan_to_value_per, Fixnum

class Bgroup # Building Group
   property :title, String
   property :creation, Date
   belongs_to :project

class Report
   property   :startd,            Date
   property   :currentd,          Date
   property   :endd,              Date
   property   :period,            Fixnum # 1="Monthly", 2="Bi-monthly", ...
   belongs_to :project

class CashflowReport < Report
   property  :title_row_a, String
   property  :title_row_b, String

   def calculation

class TenantRollReport < Report
   property :title_col, String

   def calculation

1. The line has_one Bgroup creates in the Project table a bgroup_oid and 
in the Bgroup table a project_oid. Inheritance creates in ForeignProject 
and DomesticProject tables a bgroup_oid column per each too.
2. The line has_many :reports creates in the Report table a project_oid
and inheritance creates in the subclasses of the Report a project_oid

1. Suppose the following code occurs (just note that you never use Report 
or Project but only the subclasses)
----------------------------- code -----------------------
fp = ForeignProject.new
fp.bgroup_oid = session[:bgroup_oid] # I get it from somewhere
bg = Bgroup[session[:bgroup_oid]].project_oid = fp.oid
# PROBLEM-1: Maybe the above line should somehow be automatically 
# performed

project = bg.project
# PROBLEM-2: The above line returns the project, but we do not know to 
# which subclass it corresponds. I am not sure if
project.class # WORKS?

----------------------------- code --------------------------
rp = CashflowReport.new
rp.project_oid = fp.oid

project = rp.project
# PROBLEM-3: Same as above, but in this case Og fails 100%
# rp.project searches the Project table instead of the ForeignProject

1. For each subclass add foreign keys like this:

a) in Bgroup, foreignproject_oid, domesticproject_oid and automatically 
set the correct one, based on the .class of the assignment
b) in CashflowReport do the same like in a)
c) in Report and Project add functions for querying the subclassess...

I am not sure if the above makes sense, but I believe they have to be 
resolved if Og is to be the No1 tool ;-)


Ps. one more email to follow about types of properties

Emmanouil Piperakis (epiperak at cs.ntua.gr)
{To explore is Human, to Create is Devine,
  To teach is Primal, to Rule is Sin}

More information about the Nitro-general mailing list