Closed abdullah-almesbahi closed 9 years ago
@cadr-sa Hi! In this case I'm always write some helper method like this
public static function getAttribute($model, $attribute)
{
return isset($model['translation'][$attribute]) ? $model['translation'][$attribute] : $model[$attribute];
}
$rows = static::find()
->orderBy('parent_id ASC, sort_order ASC')
->asArray()
->all();
foreach($rows as $model){
echo SomeClass::getAttribute($model, 'name');
}
I have found this in your test directory and it is worked for me , but it's ugly hack. Any idea to improve this?
public function testFindPosts()
{
$data = [];
$models = Post::find()->multilingual()->all();
foreach ($models as $model) {
$this->assertEquals($model->title, $model->title_ru);
$this->assertEquals($model->body, $model->body_ru);
$this->assertNotNull($model->title_en);
$this->assertNotNull($model->body_en);
$data[] = $model->toArray([], ['translations']);
}
$this->assertEquals(require(__DIR__ . '/data/test-find-posts.php'), $data);
}
Thank you for your fast reply , I'm trying to find out a better way without using additional method to make it work
just with asArray()
@cadr-sa To implement this we should directly modify generated sql query
why we shouldn't do it then?
@cadr-sa This will break backward compatibility
Thank you for explanation.
Hello , I was testing multilingual behavior. It's working great , but when I use asArray() , it doesn't work with it.
is there any work around for this issue ?