I have watched the movies and read the documents but I can't understand the usage of hasone and hasmany in agile toolkit! can anybody give me some simple examples for these?
Thanks.
I have watched the movies and read the documents but I can't understand the usage of hasone and hasmany in agile toolkit! can anybody give me some simple examples for these?
Thanks.
Two models with hasOne relation:
class Model_User extends Model_Table {
public $table = 'user';
function init() {
parent::init();
$this->addField('name');
$this->addField('email');
$this->hasOne('role'); // field role_id in database
}
}
class Model_Role extends Model_Table {
public $table = 'role';
function init() {
parent::init();
$this->addField('name');
}
}
Usage of these two models:
$cr = $this->add('CRUD');
$cr->setModel('Model_User',
array('name','email','role_id'),
array('name','email','role')
);
In Grid you will see field name from role table.
In Form you will see dropdown with all roles in it. You can select one role per user.
Read Agile Toolkit low-level documentation here:
http://agiletoolkit.org/book.pdf
should help you understand models fully.