Zend_db 连接表连接查询
不知道为什么我无法弄清楚这一点。基本上,我有两个具有多对多关系的表,因此它们之间有一个连接表。
例如,考虑以下数据库模式:
Restaurant (id, restaurant_name, suburb)
RestaurantCuisine (restaurant_id, cuisine_id)
Cuisine (id, cuisine_name)
因此,许多餐馆可以有多种菜系。
我试图构建的查询将返回郊区中存在的所有美食。 SQL 示例如下:
SELECT cuisine_name
FROM CuisineRestaurant
JOIN Cuisine ON Cuisine.id = CuisineRestaurant.cuisine_id
JOIN Restaurant ON Restaurant.id = CuisineRestaurant.restaurant_id
WHERE suburb LIKE '%x%';
这对我来说似乎很有意义。
我如何使用 Zend_Db 来实现这个?
Not sure why I can't figure this one out. Basically, I have two tables with a many-to-many relationship so I have a junction table inbetween them.
For an example, consider the following database schema:
Restaurant (id, restaurant_name, suburb)
RestaurantCuisine (restaurant_id, cuisine_id)
Cuisine (id, cuisine_name)
So, many restaurants can have many cuisines.
The query I am trying to construct will return all the cuisines that exist in a suburb. A SQL example is as follows:
SELECT cuisine_name
FROM CuisineRestaurant
JOIN Cuisine ON Cuisine.id = CuisineRestaurant.cuisine_id
JOIN Restaurant ON Restaurant.id = CuisineRestaurant.restaurant_id
WHERE suburb LIKE '%x%';
This seems to make sense to me.
How do I do implement this using Zend_Db?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是 Zend_Db_Select 查询版本:
结果:
您说查询运行缓慢。您是否正确配置了主键和索引?
Here's the Zend_Db_Select query version:
The result:
You said that the query runs slow. Do you have primary keys and indexes configured correctly?
我遇到了同样的问题,像这样的查询运行速度非常慢,我认为问题在于 zend 是如何制作的。
$select = Zend_Db_Table::getDefaultAdapter()->select();
I got same problem the query like this run very slow, and I think problem is with how is made by zend.
$select = Zend_Db_Table::getDefaultAdapter()->select();