Symfony 具体表继承
我正在开发基于 Symfony-Doctrine 的应用程序。我使用了具体表继承策略。但是现在我遇到了一些问题。我有下表:
产品:具有一些属性
计算机:扩展产品。
笔记本:扩展计算机。
Ipad:扩展计算机。
....等等..许多不同类别的表格。我有以下问题。任何人都可以帮忙或提供来源吗?
在我的主页中,我有一个搜索框,可以根据产品名称进行搜索。我必须为哪个表编写搜索查询?
第二个问题。再次在我的主页中,我查看了不同表中的一些产品。然后用户单击这些产品之一。我将如何决定它的表ID?
I am developing Symfony-Doctrine based application. I used Concrete Table Inheritance strategy.But now I faced with some problems. I have following tables:
Product : has some properites
Computer : Extends product.
Notebook : extends Computer.
Ipad : extends Computer.
....an so on.. many tables with different categories.I have following questions.Can anyone help or give a source please?
In my main page I have search box which does search according to product name. For which table I have to write search query?
Second question. Again in my main page I have viewed some products from different table.Then user clicks one of these product. How I will decide which table ID its?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
具体继承可能为您提供最干净的模式,但它不允许您查询多个表。因此,通过具体继承,您必须为每个子模型类编写查询,并合并结果。
如果我是你,我会阅读此页面有关 symfony 中的搜索,并编写一个lucene查询来实现这个多类搜索。它会更快,而且可能更容易。
您的产品的路径应如下所示: /product/:product_category/:product_subcategory/id 您无法找到 ID 可能在表中不唯一的产品。
Concrete inheritance gives you maybe the cleanest schema, but it does not allow you to query on several tables. So with concrete inheritance, you must write your query for each child model class, and merge the results.
If I were you, I would read this page about the search in symfony, and write a lucene query to achieve this multi-class search. It will be faster, and might be easier.
The route for your product shoud look like this : /product/:product_category/:product_subcategory/id You can't find your product with an ID which may not be unique across tables.