Yii Framework Forum: Activedataprovider Query Activerecord Hasmany Viatable - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Activedataprovider Query Activerecord Hasmany Viatable Please help me

#1 User is offline   zinzin day 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 13
  • Joined: 27-December 10

Posted 29 August 2013 - 09:09 AM

Model ArticleTag:
    public function getArticles()
    {
        return $this->hasMany('Article', array('id' => 'pid'))->viaTable('{{%article_tag_article}}', array('tid' => 'id'));
    }


Controller: $id = 3
public function actionTag($id)
    {
        $tag = ArticleTag::find($id);
        /* @var $tag ArticleTag */
        if (!$tag){
            throw new HttpException('404', 'Tag was not found.');
         }
//print_r($tag->articles); return success results
        $dataProvider = new ActiveDataProvider(array(
            'query' => $tag->getArticles(),
            'sort' => array(
                'attributes' => array(
                    'created' => array('default' => Sort::ASC),
                    'views' => array('default' => Sort::DESC),
                    'comments' => array('default' => Sort::DESC),
                )
            )
        ));
        return $this->render('tag', array('tag' => $tag, 'dataProvider' => $dataProvider));
    }


Error:

Quote

SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens The SQL being executed was: SELECT * FROM `tbl_article_tag_article` WHERE (`tid`='3') AND (`tid`='3')


Please help me use ActiveDataProvider with relate via or viaTable

Thanks advanced
0

#2 User is offline   zinzin day 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 13
  • Joined: 27-December 10

Posted 29 August 2013 - 12:39 PM

$query = $tag->getArticles();
$query2 = clone $query;
$count  = $query2->count();
print_r($tag->getArticles()->all()); //result success
print_r($query->all()); //get an error

0

#3 User is offline   CeBe 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 519
  • Joined: 16-July 10
  • Location:Berlin. Germany

Posted 01 November 2013 - 12:06 PM

Can you please try with the latest version and report the issue on github if it persists?
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users