开发者

When does STI make sense? We are storing the same information for every type but using it differently

So I know STI is the most reviled thing ever but I have an instance where I think it might actually make sense. My app is parsing a bunch of different types of xml files. Every file model stores the exact same information. Just some info about what user it is associated with, when it was uploaded, and where it is stored on S3.

After the xml开发者_如何学运维 file gets stored then I parse it for information which I use to create various other models. Each type of file is going to create different things. It is possible there could be 100 or more different types of xml files although I don't think I'm going to write parsers for that many. Does STI make sense in this case?

The downside I guess is models are all in one directory so it is going to flood that directory unless hack Rails and stick it in a subdir in models dir.

The other option is I have a kind field and put something in the lib directory that handles all this. Or I'm using resque, maybe every xml file parser should be it's own job. There are drawbacks to that though like it being kind of awkward to force a job in the rails console.


From your explanation, the 'file' model is only storing the results of the file upload process and associated meta data. Without more information about the other kinds of models being generated from the parsed XML data, I don't see why single table inheritance applies to this use case.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜