通过更改模型中的条件来解决 hasAndBelongsToMany 问题
我通过动态更改 hasAndBelongsToMany 条件来选择博客条目,它对 cakephp 1.3 不再适用。 奇怪的问题,因为它在 1.2 上工作得很好,在模型中,我通过放置一个带有静态 id 的条件来测试它,看看会发生什么,(Tag.name => 'libros')
。但它通过了 hasAndBelongsToMany 条件。不管什么结果都给我带来。
var $hasAndBelongsToMany = array('Tag' =>
array('className' => 'Tag',
'joinTable' => 'blogs_tags',
'foreignKey' => 'blog_id',
'associationForeignKey'=> 'tag_id',
'conditions' => '',
'order' => '',
'limit' => '',
'unique' => true,
'finderSql' => '',
'deleteQuery'=> ''
)
在控制器中
$this->Blog->bindModel(array(
'hasAndBelongsToMany' => array(
'Tag' => array('conditions'=>array('Tag.name'=>'libros'))
)));
$this->Blog->find('all');
现在我不再有 mysql 错误,但我有其他记录和其他结果。诡异的。
I select Blog entries by changing hasAndBelongsToMany conditions on the fly, it doesnt work anymore for me with cakephp 1.3.
Strange problem cause it was working fine with 1.2, in the model i test it by putting a condition with a static id to see what happen, (Tag.name => 'libros')
. but it pass though the hasAndBelongsToMany condition. Bring me whatever results.
var $hasAndBelongsToMany = array('Tag' =>
array('className' => 'Tag',
'joinTable' => 'blogs_tags',
'foreignKey' => 'blog_id',
'associationForeignKey'=> 'tag_id',
'conditions' => '',
'order' => '',
'limit' => '',
'unique' => true,
'finderSql' => '',
'deleteQuery'=> ''
)
in the controller
$this->Blog->bindModel(array(
'hasAndBelongsToMany' => array(
'Tag' => array('conditions'=>array('Tag.name'=>'libros'))
)));
$this->Blog->find('all');
Now i dont have mysql error anymore , but i have others records with others results. Weird.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您有正确的数据库结构,则必须使用 this=
您可以在以下位置阅读有关此内容的更多信息:
http://book.cakephp.org/view/1044/hasAndBelongsToMany-HABTM
If you have a correct database structure, must use this=
you can read more about this at :
http://book.cakephp.org/view/1044/hasAndBelongsToMany-HABTM