0

I have found the new method of adding and expression to a model using ATK4.2.1 but I am having problems adding this to a CRUD view by without getting error "Method is not defined for this object".

Is this possible? Can an expression be viewed in a CRUD object?

Model Code

->addExpression('books_written')->set(function($select){
  return $select->dsql()
    ->table('book')
    ->field($select->expr('count(*)'))
    ->where('author_id',$select->getField('id'));
}
});

Page Method that causes the error by the addition of 'isUser' to the field list.

$crud = $AddressBook->add('CRUD');
$crud->setModel('PersonLockedAccount',array('firstName','lastName','email','mobile','isUser'))->addCondition('account_id',$accountId)->addCondition('id','!=',$personId);
Micheal
  • 105
  • 7
  • it certainly can. Try creating model object first, and adding condition to it before setModel(), there seems to be an issue with setModel()->addCondition(), but I haven't fully tested it. – romaninsh Aug 16 '12 at 09:43

1 Answers1

1

There is a bug on documentation page. All the callback methods in Agile Toolkit receive a "Caller" as a first argument. In this case it would be the model itself. The second argument is query, which is in progress. It does not matter which dsql you use for the expression:

->addExpression('books_written')->set(function($model,$select){
//                                             ^^^^^^
  return $select->dsql() // creates new, empty dsql
    ->table('book')
    ->field($select->expr('count(*)'))
    ->where('author_id',$select->getField('id'));
}
});
romaninsh
  • 10,606
  • 4
  • 50
  • 70