假设我的架构看起来类似于以下内容 -
<?xml version="1.0" encoding="UTF-8" ?>
<table name="vegetables" phpName="Vegetable">
<column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true" />
<column name="name" type="varchar" required="true" />
<behavior name="i18n">
<parameter name="i18n_columns" value="name" />
</behavior>
</table>
在我的控制器类中,我会做这样的事情来获取Vegetable
对象。
$vegetables = VegetableQuery::create()->joinWithI18n($locale = 'en_US')->find(); //To get all vegetables
//or
$vegetables = VegetableQuery::create()->orderById()->joinWithI18n($locale = 'en_US')->find(); //To get all vegetables order by id
//And then to iterate I would do something like follow -
foreach($vegetables as $vegetable){
//Do something with $vegetable here
}
现在问题是如果我想在这种情况下用i18n列(即名称)命令我的查询,我应该如何查询。
我找到了另一种解决方案如下 -
$vegetables_i18n = VegetableI18nQuery::create()->orderByName('asc')->filterByLocale('en_US')->joinVegetable()->find();
// And then to iterate all the vegetables I would do something like follow
(foreach $vegetables_i18n as $vegetable_18n){
$vegetable = $vegetable_18n->getVegetable();
//Do something $vegetable here
}
我真的很想知道是否还有其他方法可以为i18n列命令vegetables
编写查询。 (更准确地说,我想在上面的VegetableQuery
类而不是上面的VegetableI18nQuery
类上写一个查询。)
非常感谢您能提供帮助。
答案 0 :(得分:0)
我通过以下方式找到了答案 -
$vegetables = VegetableQuery::create()->joinWithI18n($locale = $propel_locale)->orderBy('VegetableI18n.name', 'asc' );