The "syntax" is different, conditions should be an array like
array('account_type = ?', 'A')
phpactiverecord: get objects related by condition
-
12-12-2021 - |
Вопрос
I'm using ActiveRecord with a database already exists. I need get all accounts related with a personan with account_type = 'A' so I have:
class Person extends ActiveRecord\Model {
static $has_many = array(
array(
'accounts',
'conditions' => array('account_type = ?' => array('A')),
'class_name' => 'Accounts',
'foreign_key' => 'idpersona'
)
);
But I get the error No bound parameter for index 3
. I tried to remove the line 'conditions' => array('account_type = ?' => array('A'))
and the app works fine. What I am doing wrong?
Решение
Другие советы
The following should work. Notice the change of array('A') to simply 'A'.
class Person extends ActiveRecord\Model {
static $has_many = array(
array(
'accounts',
'conditions' => array('account_type = ?' => 'A'),
'class_name' => 'Accounts',
'foreign_key' => 'idpersona'
)
);
You only need the values in an array if your query requires a series of input or you have multiple tokens to replace.
Check out the examples here: http://www.phpactiverecord.org/projects/main/wiki/Finders#conditions
My own solution:
class Person extends ActiveRecord\Model {
static $has_many = array(
array(
'accounts',
'conditions' => "account_type = 'A'",
'class_name' => 'Accounts',
'foreign_key' => 'idpersona'
)
);
Не связан с StackOverflow