我正在使用数据库已经存在的ActiveRecord。我需要获取与account_type = 'A‘的角色相关的所有帐户,所以我有:
class Person extends ActiveRecord\Model {
static $has_many = array(
array(
'accounts',
'conditions' => array('account_type = ?' => array('A')),
'class_name' => 'Accounts',
'foreign_key' => 'idpersona'
)
);但是我得到了错误No bound parameter for index 3。我尝试删除行'conditions' => array('account_type = ?' => array('A')),但应用程序运行正常。我做错了什么?
发布于 2012-12-26 22:43:45
“语法”是不同的,条件应该是像array('account_type = ?', 'A')这样的数组
发布于 2012-12-26 21:37:11
下面的方法应该是可行的。注意数组( 'A‘)改为简单的’A‘。
class Person extends ActiveRecord\Model {
static $has_many = array(
array(
'accounts',
'conditions' => array('account_type = ?' => 'A'),
'class_name' => 'Accounts',
'foreign_key' => 'idpersona'
)
);只有当查询需要一系列输入或者有多个标记要替换时,才需要数组中的值。
在这里查看示例:http://www.phpactiverecord.org/projects/main/wiki/Finders#conditions
发布于 2012-12-26 23:09:08
我自己的解决方案:
class Person extends ActiveRecord\Model {
static $has_many = array(
array(
'accounts',
'conditions' => "account_type = 'A'",
'class_name' => 'Accounts',
'foreign_key' => 'idpersona'
)
);https://stackoverflow.com/questions/14041202
复制相似问题