nandosola / dilithium-rb

A tiny framework to power your enterprise-ish stuff in Ruby
BSD 3-Clause "New" or "Revised" License
3 stars 3 forks source link

Ability to rename children #19

Open mcamou opened 10 years ago

mcamou commented 10 years ago

Currently the class name of the children entities is inferred from the name. It would be useful to be able to rename the children (similar to the way references work). For example:

class Company < BaseEntity
  attribute :name, String
  children :foo_departments, Department
  children :bar_departments, Department
end
nandosola commented 10 years ago

It's OK that "references" and "multi_references" have an optional class to point to, so that the attribute's name can be more flexible. However, IMHO doing the same thing with "children" could be dangerous, since here we'd be dealing with an inheritance scenario:

class Department < BaseEntity
 #...
end

class Company < BaseEntity
  children :local_department, :remote_department
  #...
end

class LocalDepartment < Department;  parent :company; end
class RemoteDepartment < Department;  parent :company; end

In the scenario above, the serialization to a relational DB could be implemented via an InheritanceMapper that handles either one of these:

WDYT?

mcamou commented 10 years ago

We can have another scenario:

class Department < BaseEntity
  children :employees
  children :managers, Employee
end

class Employee < BaseEntity
  parent :department
end

This could be resolved either by:

(using CTI or STI)

class Employee < BaseEntity
  parent :department
end

class Manager < Employee
  def self.promote(an_employee)
    # Use an_employee as a prototype
  end
end

Or (using references):

class Department < BaseEntity
  children :employees
  reference :manager, Employee
end