ATK CRUD有一个:很多关系

时间:2014-01-08 17:11:57

标签: atk4

im begginer和搜索文档,但无法找到如何执行此操作:

我有两个表,管理员和应用程序。管理员可以有很多应用程序。

ADMIN:

class Model_Admin extends Model_Table {
    public $entity_code='admin';
    function init(){
        parent::init(); 

        $this->addField('name');
        $this->addField('email');
        $this->addField('password')->type('password');
        $this->addField('active')->type('boolean')->system(true);
        $this->addField('super')->type('boolean')->system(true);
        $this->addField('created')->type('timestamp')->defaultValue($this->dsql()->expr('now()'))->system(true);
        $this->addField('updated')->type('timestamp')->system(true);

        $this->hasMany('Application','admin_id');
        //$this->hasOne('Application');

        $this->addHook('beforeSave',function($m){
                 $m['updated']=$m->dsql()->expr('now()');
                });
    }
} 

应用程序:

class Model_Application extends Model_Table {
    public $entity_code='application';
    function init(){
        parent::init(); 

        $this->addField('name');
        $this->addField('fbid');
        $this->addField('fbsecret');
        $this->addField('active')->type('boolean')->system(true);
        $this->addField('created')->type('timestamp')->system(true);
        $this->addField('updated')->type('timestamp')->system(true);
    }
}

第一个问题,当我生成sql代码(/generate.html)时,它不会产生一对多的关系。 其次,在页面上我添加了CRUD:

$this->add('CRUD')->setModel('Admin');

但是对于任何一个人都没有暗示。我希望它在添加按钮表单上,但也没有什么?

我想要的是,我可以添加管理员,并选择属于他的应用程序吗?

谢谢你的帮助!

1 个答案:

答案 0 :(得分:2)

Model_Application中的

  $this->hasOne('Admin');
页面上的

   $this->add('CRUD')->setModel('Application');

在CRUD的编辑形式中,您将看到所有管理员的下拉菜单,您将能够为每个应用程序设置管理员