有人知道如何在 PHP symfony1.4 中处理数据库 View 吗?
我已在数据库中手动创建了一个 View “ABC”。 现在,我想从该 View “ABC”中选择记录,并在查询中添加 where 子句。 如果可以的话请举例。
编辑:
我的架构是:
Product:
columns:
name: { type: string(127), notnull: true }
launch_date: { type: date }
price: { type: integer }
status_id: { type: integer }
ProductLocation :
product_id: { type: integer }
name: { type: string(50) }
launch_date: { type: date }
relations:
Product: {onDelete: RESTRICT, local: product_id, foreign: id, foreignAlias: "Products" }
我想创建两个表的并集 View 。 谢谢
最佳答案
您只需在 schema.yml
中定义 View ,其中包含您在数据库中手动创建的所有内容。
然后重建您的架构(php symfonydoctrine:build --model
),您将能够使用 Doctrine 函数访问您的 View 。但是,如果您尝试在此 View 中创建任何内容,则会收到错误消息,这是正常的。
如果您提供有关您的 View 的更多信息(字段、名称等..),我可以提供示例
编辑:
顺便问一下,您在 Google 上搜索过吗?
它们都解释了如何从查询创建 View ,然后使用它来浏览结果,但我几乎确定您可以使用我上面描述的方法。
编辑2:
在模式中定义的 View 与定义真实表完全相同,尝试使用类似的东西(调整内部字段):
Product_ProductLocation:
columns:
name: { type: string(127), notnull: true }
launch_date: { type: date }
price: { type: integer }
status_id: { type: integer }
product_id: { type: integer }
关于php - 如何使用 Symfony 处理数据库 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12913858/