Yii Framework Forum: Aneh bin ajaib apa Bugs ya?? - Yii Framework Forum

Jump to content

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

Aneh bin ajaib apa Bugs ya?? Rate Topic: -----

#1 User is offline   Dan Din Dun 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 77
  • Joined: 09-February 10

Posted 24 March 2010 - 11:54 AM

begini pak.

saya punya 3 tabel

tbx_Debtors         tbx_Watchlist                       tbx_Members    
id (PK)             id (PK)                             id (PK)
name                debtor_id  (FK tbx_Debtors)         name
                    member_id   (FK tbx_Members)         


jadi fungsi tbx_Watchlist itu seperti Bookmark dapat memiliki banyak member maupun debtors.
yang ingin saya lakukan adalah menampilkan data Debtor yang di Bookmark/ di watchlist oleh member dengan id = X.

misal isi datanya:
tbx_Debtors         tbx_Watchlist                       tbx_Members
id | name           id  |  debtor_id  | member_id       id  |  name
1  | Ronaldo        1   |   2         |    2             1  |  Tukang Kredit 1
2  | Messi          2   |   3         |    2             2  |  Tukang Kredit 2
3  | Toti           3   |   3         |    3             3  |  Tukang Kredit 3


nah jadi saya ingin menampilkan data2 debtor yang dimiliki oleh "Tukang Kredit 2"
kurang lebih queynya mungkin seperti ini:
SELECT * FROM tbx_Debtors as a INNER JOIN tbx_Watchlist as b ON a.id = b.debtor_id WHERE b.member_id = 2


yang sudah saya lakukan adalah:

di model/Debtors.php
    
...
public function relations(){
        return array(
            'Watchlist' => array(self::HAS_MANY,'Watchlist','debtor_id','joinType' => 'INNER JOIN')
        );
}
...


kemudian di Watchlist.php
...
    public function relations(){
        return array(
            'Members' => array(self::BELONGS_TO,'Members','id'),
            'Debtors' => array(self::BELONGS_TO,'Debtors','id')
        );
    }
...


lalu di controller index.php
...
    public function actionWatchlist(){
        $criteria = new CDbCriteria();
        $criteria->condition = 'Watchlist.member_id = :member_id' ;
        $criteria->params = array(':member_id' => Yii::app()->user->getId());
        $pages = new CPagination(Debtors::model()->with('Watchlist')->count($criteria));
        $pages->pageSize = 10;
        
        $pages->applyLimit($criteria);
        $criteria->limit = $pages->getLimit();

        $model = Debtors::model()->with('Watchlist')->findAll($criteria);
        $this->render('watchlist',array(
                'model' => $model,
                'pages' => $pages
            ));
    }
...


nah dari code2 yang saya kerjakan diatas menghasilkan error seperti ini:
CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Watchlist.member_id' in 'where clause'


ketika saya aktifkan CLogRouter, disitu query yang dihasilkan oleh Debtors::model()->with('Watchlist')->findAll($criteria) tidak men-join table Watchlist. hanya men-Select Debtor tapi menyertakan Where Watchlist. sehingga terjadi error seperti diatas "Unknown Watchlist.member_id"??? ANEHHHH

ketika saya hilangkan baris
$criteria->limit = $pages->getLimit();


masalah diatas hilang query yang dihasilkan Debtors::model()->with('Watchlist')->findAll($criteria) berjalan baik.

bener2 aneh..... ada yang tahu masalahnya dimana? tolong ya Master2..

Thx
----
Thanks and Kind Regards
------
DanDinDun
0

#2 User is offline   Dan Din Dun 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 77
  • Joined: 09-February 10

Posted 24 March 2010 - 10:03 PM

View PostDan Din Dun, on 24 March 2010 - 11:54 AM, said:

begini pak.

saya punya 3 tabel

tbx_Debtors         tbx_Watchlist                       tbx_Members    
id (PK)             id (PK)                             id (PK)
name                debtor_id  (FK tbx_Debtors)         name
                    member_id   (FK tbx_Members)         


jadi fungsi tbx_Watchlist itu seperti Bookmark dapat memiliki banyak member maupun debtors.
yang ingin saya lakukan adalah menampilkan data Debtor yang di Bookmark/ di watchlist oleh member dengan id = X.

misal isi datanya:
tbx_Debtors         tbx_Watchlist                       tbx_Members
id | name           id  |  debtor_id  | member_id       id  |  name
1  | Ronaldo        1   |   2         |    2             1  |  Tukang Kredit 1
2  | Messi          2   |   3         |    2             2  |  Tukang Kredit 2
3  | Toti           3   |   3         |    3             3  |  Tukang Kredit 3


nah jadi saya ingin menampilkan data2 debtor yang dimiliki oleh "Tukang Kredit 2"
kurang lebih queynya mungkin seperti ini:
SELECT * FROM tbx_Debtors as a INNER JOIN tbx_Watchlist as b ON a.id = b.debtor_id WHERE b.member_id = 2


yang sudah saya lakukan adalah:

di model/Debtors.php
    
...
public function relations(){
        return array(
            'Watchlist' => array(self::HAS_MANY,'Watchlist','debtor_id','joinType' => 'INNER JOIN')
        );
}
...


kemudian di Watchlist.php
...
    public function relations(){
        return array(
            'Members' => array(self::BELONGS_TO,'Members','id'),
            'Debtors' => array(self::BELONGS_TO,'Debtors','id')
        );
    }
...


lalu di controller index.php
...
    public function actionWatchlist(){
        $criteria = new CDbCriteria();
        $criteria->condition = 'Watchlist.member_id = :member_id' ;
        $criteria->params = array(':member_id' => Yii::app()->user->getId());
        $pages = new CPagination(Debtors::model()->with('Watchlist')->count($criteria));
        $pages->pageSize = 10;
        
        $pages->applyLimit($criteria);
        $criteria->limit = $pages->getLimit();

        $model = Debtors::model()->with('Watchlist')->findAll($criteria);
        $this->render('watchlist',array(
                'model' => $model,
                'pages' => $pages
            ));
    }
...


nah dari code2 yang saya kerjakan diatas menghasilkan error seperti ini:
CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Watchlist.member_id' in 'where clause'


ketika saya aktifkan CLogRouter, disitu query yang dihasilkan oleh Debtors::model()->with('Watchlist')->findAll($criteria) tidak men-join table Watchlist. hanya men-Select Debtor tapi menyertakan Where Watchlist. sehingga terjadi error seperti diatas "Unknown Watchlist.member_id"??? ANEHHHH

ketika saya hilangkan baris
$criteria->limit = $pages->getLimit();


masalah diatas hilang query yang dihasilkan Debtors::model()->with('Watchlist')->findAll($criteria) berjalan baik.

bener2 aneh..... ada yang tahu masalahnya dimana? tolong ya Master2..

Thx
----



ada yang bisa bantu?
Thanks and Kind Regards
------
DanDinDun
0

#3 User is offline   rifqi 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 04-November 08

Posted 30 March 2010 - 11:37 PM

Mungkinkah ini ya?
$criteria->condition = 'Watchlist.member_id = :member_id' ;


diganti
$criteria->condition = 'tbx_Watchlist.member_id = :member_id' ;


blm tak coba juga ...
0

Share this topic:


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

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