/**
* @return \yii\db\ActiveQuery
*/
public function getCategories()
{
return $this->hasMany(Category::className(), ['id' => 'category_id'])->viaTable(ProductCategory::tableName(), ['product_id' => 'id']);
}
/**
* @param $value
*/
public function setCategories($value)
{
$this->categories = $value;
}
$users = Users::model()->findAll();
$user = Users::model()->findByPk($id);
class Users extends CActiveRecord
{
…
public function relations()
{
return array(
'messages'=>array(self::HAS_MANY, 'Messages', 'user_id')
);
}
}
$user->messages