0

I'm using the containable behavior to look at several tables.

    $this->paginate = array(
        'contain' => array(
            'Co' => array('fields' => array('ref')),
            'CoItemType' => array('fields' => array('name')),
            'Casing' => array(
                'fields' => array('id','barcode','CONCAT(plant_dot,size_dot,product_line_dot,production_week) as dot'),
                'Customer' => array('fields' => array('company_name')),
            )
        )
    );

This works as expected. However I am integrating this with jQuery datatables and the way dataTables passes over conditions it does not specifiy a field. So I'd like to do conditions outside of the contains like so...

    'conditions' = array(
        'OR' => array(
            array("Table.field_name LIKE " => '%'.$parameter.'%'),
            array("Table.field_name LIKE " => '%'.$parameter.'%'),
            array("Table.field_name LIKE " => '%'.$parameter.'%')
        )
    )

Of course this is not possible since the containable behavior wants you to include the conditions under the tables key in the contain array. This is frustrating, does anyone have a solution or workaround around to this problem?

I am using CakePHP 2.x

cnizzardini
  • 1,196
  • 1
  • 13
  • 29
  • tip: use virtual fields here for your CONCAT. this way you get a cleaner result array. – mark Jan 22 '13 at 16:52
  • It's a nice tip, but does little to solve the limitations of the containable behavior. CakePHP simple can't do this because it splits containables into multiple queries. I'd be better off writing the SQL myself. – cnizzardini Jan 22 '13 at 17:21
  • use linkable or some other behavior then or custom-bind your joins. this way you can still use the wrapper methods here. – mark Jan 22 '13 at 17:22
  • This LinkableBehavior works great (https://github.com/Terr/linkable/blob/master/models/behaviors/linkable.php) however the project has not been updated in years and was originally designed for 1.3. Is there a LinkableBehavior like this that is still maintained? – cnizzardini Jan 22 '13 at 18:44
  • try google for it. I bet there are a lot of 2.x ones out there like https://github.com/dereuromark/tools/blob/2.0/Model/Behavior/LinkableBehavior.php – mark Jan 22 '13 at 19:36

1 Answers1

0

Use Linkable Behavior as noted in comments.

cnizzardini
  • 1,196
  • 1
  • 13
  • 29