2008年9月2日星期二

Re: [fw-db] Re: Re[fw-db] lated tables reference error

Hello Bill,
Thank you for your response. I'm using ZF 1.5 on PHP 5.2.6. I copied and pasted only a small portion of the code, below is the full code:

Articles.php:
<?php

/**
 * ArticlesModel
 *  
 * @author humansky
 * @version 
 */

require_once 'Zend/Db/Table/Abstract.php';

class Articles extends Zend_Db_Table_Abstract {
/**
 * The default table name 
 */
protected $_name = 'articles';
protected $_dependentTables = array('ArticlesKeywords');
}

Keywords.php:
<?php

/**
 * KeywordsModel
 *  
 * @author humansky
 * @version 
 */

require_once 'Zend/Db/Table/Abstract.php';

class Keywords extends Zend_Db_Table_Abstract {
/**
 * The default table name 
 */
protected $_name = 'keywords';
protected $_dependentTables = array('ArticlesKeywords');
}

ArticlesKeywords.php
<?php

/**
 * ArticlesKeywords
 *  
 * @author humansky
 * @version 
 */

require_once 'Zend/Db/Table/Abstract.php';

class ArticlesKeywords extends Zend_Db_Table_Abstract {
/**
 * The default table name 
 */
protected $_name = 'articles_keywords';

protected $_referenceMap = array (
'Keywords' => array (
'columns' => array ('keyword_id' ), 
'refTableClass' => 'Keywords'
'refColumns' => array ('id' ) ), 
'Articles' => array (
'columns' => array ('article_id' ), 
'refTableClass' => 'Articles'
'refColumns' => array ('id' ) ) 
);
}

Then in ArticlesController.php under the editArticle() action I have the following code snippet:
$id = ( int ) $this->_request->getParam ( 'id'0 );
if ($id > 0) {
$articles = new Articles ( );

//fetch articles, keywords, categories, and related associations
$rowset = $articles->find ( $id );
$rowset->current()->findManyToManyRowset('Keywords''ArticlesKeywords');

//populate table with data
$form->populate ( $rowset->toArray() );
}

I just made both article_id and keyword_id PRIMARY KEYs and I will remove the $_dependentTables from the Articles and Keyword models. But I still get the same error. Could it be how I defined the database? Should I possibly recreate the data model and make sure I REFERENCE the correct foreign keys?

Thank you,
Henry

没有评论: