Commit e5919cf4 by Paul Klimov

Merge pull request #4034 from klimov-paul/4018-sphinx-db-relation-composite-link

Fix #4018: sphinx db relation composite link
parents 06235cd1 88717511
......@@ -618,8 +618,13 @@ abstract class ActiveRecord extends BaseActiveRecord
{
$columns = static::getIndexSchema()->columns;
foreach ($row as $name => $value) {
if (isset($columns[$name]) && $columns[$name]->isMva) {
$row[$name] = explode(',', $value);
if (isset($columns[$name])) {
if ($columns[$name]->isMva) {
$mvaValue = explode(',', $value);
$row[$name] = array_map(array($columns[$name], 'typecast'), $mvaValue);
} else {
$row[$name] = $columns[$name]->typecast($value);
}
}
}
parent::populateRecord($record, $row);
......
......@@ -5,6 +5,7 @@ Yii Framework 2 sphinx extension Change Log
--------------------------
- Bug #3668: Escaping of the special characters at 'MATCH' statement added (klimov-paul)
- Bug #4018: AR relation eager loading does not work with db models (klimov-paul)
- Enh: Added support for using sub-queries when building a DB query with `IN` condition (qiangxue)
- Enh #3520: Added `unlinkAll()`-method to active record to remove all records of a model relation (NmDimas, samdark, cebe)
......
......@@ -18,6 +18,11 @@ class ArticleIndex extends ActiveRecord
return $this->hasOne(ArticleDb::className(), ['id' => 'id']);
}
public function getSourceCompositeLink()
{
return $this->hasOne(ArticleDb::className(), ['id' => 'id', 'author_id' => 'author_id']);
}
public function getTags()
{
return $this->hasMany(TagDb::className(), ['id' => 'tag']);
......
......@@ -42,4 +42,17 @@ class ActiveRelationTest extends SphinxTestCase
$this->assertTrue($articles[0]->index instanceof ArticleIndex);
$this->assertTrue($articles[1]->index instanceof ArticleIndex);
}
/**
* @see https://github.com/yiisoft/yii2/issues/4018
*/
public function testFindCompositeLink()
{
$articles = ArticleIndex::find()->with('sourceCompositeLink')->all();
$this->assertEquals(2, count($articles));
$this->assertTrue($articles[0]->isRelationPopulated('sourceCompositeLink'));
$this->assertNotEmpty($articles[0]->sourceCompositeLink);
$this->assertTrue($articles[1]->isRelationPopulated('sourceCompositeLink'));
$this->assertNotEmpty($articles[1]->sourceCompositeLink);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment