Bindmodel到绑定模型? CakePHP的

时间:2011-07-01 12:57:27

标签: cakephp cakephp-1.3

enter image description here

我使用bindModel方法将ProductsPhoto绑定到子节点:

$this->Category->bindModel(array
            ('hasMany' => array(
                'ProductsPhoto' => array... 

如何将ProductsPhoto绑定到每个产品项目?

或者是否有其他解决方案建议?

2 个答案:

答案 0 :(得分:2)

在你的控制器中,写下代码

$this->ProductsPhoto->bindModel('hasMany' => array('Product.productphoto_id' => 'ProductPhoto.id');

在您的ProductPhoto模型中,

var $hasMany = array(
    'Product' =>
                array(
                    'className' => 'ProductPhoto',
                    'foreignKey' => 'productphoto_id',
                    'conditions' => '',
                    'fields' => '',
                    'order' => '',
                    'counterCache' => ''
            ),  

);

答案 1 :(得分:1)

动态:$this->ProductsPhoto->bindModel('hasMany' => 'Product');

通过ProductsPhoto类属性:$hasMany = 'Product';