2

For my project management application, I am currently using Single Table Inheritance so that:

Lead < Requirement

Project < Requirement

By which I mean to say that Lead is a Requirement and Project is a Requirement. It was okay, while I had these two only. Then I had another similar thing (Tender), so I created

Tender < Requirement

Now the problem is when a Tender converts to a project there is no way for me to identify which projects were Tenders and which were Leads. So I can't say for example:

Out of 100 leads I get 20 projects and out of 100 Tenders I get 5 projects.

For now as a workaround I think I can use boolean field to say if this was a tender. But that defeats the purpose of having STI. Is there another way to do this using STI itself. Or are booleans [or some sort of category/project_type field] the only way to accomplish this.

Can I use state_machine for this?

I have been trying to get this right for some time now. Any help would be great.

Chandresh Pant
  • 1,173
  • 15
  • 19
  • I have used boolean fields and its working great. But I am still searching for a solution which will allow this in a better way. Another solution that I am thinking about is has_one, but not sure if it would work. Any suggestions? – Chandresh Pant May 30 '11 at 09:45

1 Answers1

0

As no one answered this question, I am documenting the different approaches I have / am trying. But as I try more and more I am starting to dislike STI.

  1. Use booleans to specify if a requirement is a tender/lead/project. Added benefit of being able to tick more than one. A requirement can a Tender to start with then become a Lead and then a Project.

  2. Status field: HABTM. Can check one or more statuses. Again similar to 1 but added benefit of being able to add statuses.

  3. Has one: but this one seems non-dry. Haven't tried. Adding as a theoretical option. Project has one Lead Or Project has one Tender.

  4. State-Machine: Seems like an interesting option. Not sure how I will be able to track the state changes. Can anybody with experience with State-Machine help me here?

Chandresh Pant
  • 1,173
  • 15
  • 19