Bindmodel to binded model? Cakephp

删除回忆录丶 提交于 2020-01-06 04:54:06

问题


I bind ProductsPhoto to children using bindModel method:

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

How can I bind ProductsPhoto to every product item?

Or maybe any other solution suggestion?


回答1:


in your controller ,write below code

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

in your ProductPhoto model,

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

);



回答2:


On the fly: $this->ProductsPhoto->bindModel('hasMany' => 'Product');

Via ProductsPhoto class property: $hasMany = 'Product';



来源:https://stackoverflow.com/questions/6548249/bindmodel-to-binded-model-cakephp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!