문제

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 "syntax" is different, conditions should be an array like array('account_type = ?', 'A')

다른 팁

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'
    )
);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top