-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extension crashes, when trying to use via in place of viaTable to create many-many relation #8
Comments
Can you provide a concrete config example? |
In ActiveRelationTrait.php: public function via($relationName, callable $callable = null)
{
$relation = $this->primaryModel->getRelation($relationName);
$this->via = [$relationName, $relation];
if ($callable !== null) {
call_user_func($callable, $relation);
}
return $this;
} and viaTable: public function viaTable($tableName, $link, callable $callable = null)
{
$relation = new ActiveQuery(get_class($this->primaryModel), [
'from' => [$tableName],
'link' => $link,
'multiple' => true,
'asArray' => true,
]);
$this->via = $relation;
if ($callable !== null) {
call_user_func($callable, $relation);
}
return $this;
} in ManyToManyBehavior: // many-to-many
if (!empty($relation->via) && $relation->multiple) {
//Assuming junction column is visible from the primary model connection
list($junctionTable) = array_values($relation->via->from);
list($junctionColumn) = array_keys($relation->via->link);
list($relatedColumn) = array_values($relation->link); So author trying to use "via" as object, but in case of using via('relation') in place of viaTable - via as array, and application crashed. /**
* @return \yii\db\ActiveQuery
*/
public function getCategories()
{
return $this->hasMany(Category::className(), ['id' => 'category_id'])
->viaTable('page_category', ['page_id' => 'id']);
} works good, and /**
* @return \yii\db\ActiveQuery
*/
public function getPageCategory()
{
return $this->hasMany(PageCategory::className(), ['page_id' => 'id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getCategories()
{
return $this->hasMany(Category::className(), ['id' => 'category_id'])
->via('pageCategory');
} crashes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No description provided.
The text was updated successfully, but these errors were encountered: