开发者

Rails - Single Table Inheritance problems. Any solutions / alternatives

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 proj开发者_开发问答ect 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.


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜