1

I need to set up a multiple class inheritance model here for the following models. Basically I'm building an extensible contacts directory. From a base class Contact I intend to derive other classes i.e something on the lines of :

class Contact
    # the super class
    attr_accessible :name, :about
end

class Person < Contact
    attr_accessible :first_name, last_name, :description, :works_for_company_id
end

class Company < Contact
    attr_accessible :company_name, :location, :services
end

Each model corresponds to a different table - I'm assuming that there would be a has_one belongs_to relation ship between teh parent and the child classes however I was wondering if theres a gem that can ease it a bit. Or if I have to do it myself how would I actually accomplish it.

For example contact.name is actually person.first_name+' '+person.last_name for a person or company.company_name for the company. How do I structure my database and associations to get this right?

Ali
  • 7,353
  • 20
  • 103
  • 161
  • 2
    Like this one? https://github.com/brunofrank/class-table-inheritance –  Jan 16 '13 at 13:31
  • 1
    Or this one : https://github.com/PeterHamilton/citier – siekfried Jan 16 '13 at 13:50
  • Hmmmm I've run into issues with both of them - if I want to replicate it without a gem what would be my course of action here – Ali Jan 17 '13 at 10:40
  • Whoa I think I got the hang of citier :) just needed a bit more effort on my part. Thanks for the suggestion - btw - if I were to do it without a gem what would be the way to do so? – Ali Jan 17 '13 at 11:58
  • @Ali - the really neat thing is that you can open up the code for those gems and see exactly how to do it. –  Jan 23 '13 at 13:45

0 Answers0