假设我的架构看起来类似于以下内容 -
<?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
}
我真的想知道是否还有其他替代方法来编写vegetables
按 i18n 列排序的查询。(更准确地说,我想在上面的VegetableQuery
类而不是上面的类上写一个查询VegetableI18nQuery
。)
如果您能提供帮助,我们将不胜感激。