Search code examples
activerecordcodeigniter-2

A PHP error was encountered when conditions are applied in model


I have tables

  • table1(id, name)
  • table2(id, name, active)

The field active in table2 contains value '0' or '1'

My relation in my model is

static $has_many = array(
        array('table2', 'conditions' => array('active = ?' => array(0)))
    );

Later I have to find all where

table2.active = '1'

But now I am getting error as:

A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 0

Filename: lib/Relationship.php


Solution

  • for condition value should be scalar (string, number, boolean)

    $has_many = array(
                array('table2', 'conditions' => array('active' => 0))
            );
    

    You have to use array only when using IN condition in query only.