MVC数据库设计问题 - 每个模型表1 [英] Problem With Database Design For MVC - 1 Table Per Model
问题描述
我不认为有什么关于 MVC设计模式,声明每个域类应该有一个数据库表。实际上,关于MVC的设计模式,甚至说你的模型应该被保存在一个关系数据库中,所以没有什么关系。
这只是一个策略一些流行的框架(Ruby on Rails - 也许是ASP.NET MVC?)已经采取了,为什么似乎是方便的。但它不是MVC的要求。 Spring MVC(对于Java世界)没有固有的概念,如何将模型组件映射到数据库,实际上美丽的是它不在乎 - 您只需要提供要使用的模型数据,以及您获得的位置它从MVC框架不在乎。
所以换句话说,你不需要假设MVC模式意味着你必须使用一个数据库每个模型组件的表。你甚至不需要使用数据库,你的模型也可以来自一个平面文件或Web服务(和MVC的好处是,如果你正确设计你的应用程序,你可以交换不同的数据层实现和在您的应用程序中,View或Controller 将不会知道)。
My biggest hurdle with getting started with an MVC framework has to do with with the 1 model to 1 DB table concept. To me it's overly simplistic and unrealistic for anything beyond a simple app. Yet, MVC is in use everywhere, including this awesome StackOverflow site. As is typical, all of the code examples and tutorials i come across are very simple and the 1 to 1 relationship works fine in those cases. But, what i'm looking for is a solid real world example of an MVC model that address table joins. In the case of stackoverflow, i would imagine a DB design with tables like Questions, Tags, Users, etc. In my DB design I may have a Question_Tag link table to to look up all tags associated with a given question. How does MVC deal with this?
I don't believe that there is anything about the MVC design pattern that states that there should be one database table per domain class. In fact, there is nothing about the MVC design pattern that even says that your model should be or has to be persisted in a relational database.
This is just the strategy that some popular frameworks (Ruby on Rails - maybe ASP.NET MVC too?) have taken on, for what appears to be convenience sake. But it is not a requirement of MVC. Spring MVC (for the Java world) has no inherent concept of how to map the model components to a database, in fact it's beauty is that it doesn't care - you just need to supply the model data to use, and where you get it from the MVC framework doesn't care about.
So in other words, you don't need to assume that the MVC pattern means that you have to use one database table per model component. Heck you don't even need to use a database, your model could come just as well from a flat file or web services (and what's great about MVC is that if you design your app properly, you could swap different data layer implementations in and out of your application and the View or Controller won't even know).
这篇关于MVC数据库设计问题 - 每个模型表1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!