Symfony2:按国家列出城市 [英] Symfony2: List cities by country
本文介绍了Symfony2:按国家列出城市的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我现在需要做的是呈现每个国家的列表形成此数据库与所有城市相关联。
无法确定,如何使用doctrine构建此查询。
解决方案
将OneToMany关系添加到城市和国家之间的国家,然后:
$国家 - > getCity(); //从城市表返回所有链接的城市
I have two tables, one containing cities and one containing countries. Every city is linked to a country by a ManyToOne relation (via field country_id) to a country.
What I need to do now is, to render a list of every country form this database with all cities linked to it.
Can't figure out, how to build this query using doctrine.
解决方案
Add OneToMany relation to country between city and country, then:
$country->getCity(); //return all linked cities from city table
这篇关于Symfony2:按国家列出城市的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文