Skip to content

Instantly share code, notes, and snippets.

@michaeltwofish
Created January 9, 2012 20:49
Show Gist options
  • Save michaeltwofish/1584856 to your computer and use it in GitHub Desktop.
Save michaeltwofish/1584856 to your computer and use it in GitHub Desktop.
static::applyFilter('find', function($self, $params, $chain) {
// Check if we're finding forms linked to a test
if (isset($params['options']['conditions']['test_id'])) {
$test_id = (int)$params['options']['conditions']['test_id'];
$params['options']['joins'] = array(new Query(array(
'source' => 'test_forms',
'constraint' => array ('Form.id' => 'test_forms.form_id', 'test_forms.test_id' => $test_id),
)));
unset($params['options']['conditions']['test_id']);
}
$data = $chain->next($self, $params, $chain);
if ($data instanceof Record || $data instanceof RecordSet) {
$data->setLockStatus();
}
return $data;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment